1

I have a UIViewController calling another view Controller with a defined loadView method. I’ve been trying many options without success to solve the problem of the loadView method not called.

Any help is appreciated.

Thanks. MArcos

Caller UIViewController

#import "MyAlbumViewController.h"
@interface ViewController : UIViewController
@end

implementation

#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}

- (void)viewDidAppear:(BOOL)animated{

    UIViewController*albumVC = [[MyAlbumViewController alloc] init];

    [self.navigationController pushViewController:albumVC animated:YES];


}
@end

Called UIViewController

@interface MyAlbumViewController : NIToolbarPhotoViewController <NIPhotoAlbumScrollViewDataSource>

@end

Implementation

#import "MyAlbumViewController.h"

@implementation MyAlbumViewController

- (void)loadView{

    [super loadView];

    self.photoAlbumView.dataSource = self;

    // Set the default loading image.
    self.photoAlbumView.loadingImage = [UIImage imageWithContentsOfFile:
                                        NIPathForBundleResource(nil, @"NimbusPhotos.bundle/gfx/default.png")];

    self.title = NSLocalizedString(@"Loading...", @"Navigation bar title - Loading a photo album");

    [self loadAlbumInformation];
}...
vilelam
  • 804
  • 1
  • 11
  • 19

2 Answers2

1

The idea of loadView is to completely override the method, and not call super

What you are doing is exactly what the viewDidLoad method is for, it doesn't matter if you loaded it from a nib file or whatever

And I quote from your own post, in your ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


}
Ismael
  • 3,927
  • 3
  • 15
  • 23
  • If my called UIViewController has a programmatically defined view, should I load the view from loadView or I'm wrong? – vilelam Jan 29 '13 at 19:20
  • It's not necessary to use the `loadView`. You can even create things in your `viewDidLoad` like adding a table or some buttons or whatever, because that method is called right after loadView and only when it was just created, I do it all the time :) – Ismael Jan 29 '13 at 19:24
  • I've just added a NSLog inside the viewDidLoad and no result was displayed. Also the viewDidLoad has not been called. It seems that I'm doing something wrong with the [self.navigationController pushViewController:albumVC animated:YES]; – vilelam Jan 29 '13 at 19:27
  • I changed from [self.navigationController pushViewController:albumVC animated:YES]; to [self presentViewController:albumVC animated:YES completion:nil]; – vilelam Jan 29 '13 at 19:33
  • and now its calling the loadView() and also the viewDidLoad(). – vilelam Jan 29 '13 at 19:35
0

I was pushing view controller with:

 [self.navigationController pushViewController:albumVC animated:YES];

I just changed to:

[self presentViewController:albumVC animated:YES completion:nil];

UIViewController Navigation Controller

navigationController The nearest ancestor in the view controller hierarchy that is a navigation controller. (read-only)

@property(nonatomic, readonly, retain) UINavigationController *navigationController Discussion If the receiver or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. This property is nil if the view controller is not embedded inside a navigation controller.

vilelam
  • 804
  • 1
  • 11
  • 19