문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top