[英]loadView() no called
I have a UIViewController calling another view Controller with a defined loadView method. 我有一个UIViewController用定义的loadView方法调用另一个视图控制器。 I've been trying many options without success to solve the problem of the loadView method not called. 我一直在尝试许多选项而未成功解决未调用的loadView方法的问题。
Any help is appreciated. 任何帮助表示赞赏。
Thanks. 谢谢。 MArcos MArcos
Caller UIViewController 呼叫者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 叫做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
loadView
的想法是完全覆盖该方法,而不是调用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 您正在执行的操作正是viewDidLoad
方法的用途,无论您是从nib文件还是其他文件加载它都没关系
And I quote from your own post, in your ViewController.m
我引用您在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 UIViewController导航控制器
navigationController The nearest ancestor in the view controller hierarchy that is a navigation controller. navigationController在视图控制器层次结构中最接近的祖先,它是导航控制器。 (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. @property(非原子的,只读的,保留的)UINavigationController * navigationController讨论如果接收者或其祖先之一是导航控制器的子代,则此属性包含拥有的导航控制器。 This property is nil if the view controller is not embedded inside a navigation controller. 如果视图控制器未嵌入在导航控制器内部,则此属性为nil。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.