简体   繁体   中英

loadView() no called

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];
}...

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.


}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM