【发布时间】:2012-08-07 21:44:40
【问题描述】:
我有这个级联:
应用中的某处
- (void) go
{
MyCustomViewController* controller = [[MyCustomViewController alloc] init];
controller.delegate = self;
[controller run];
}
在 MyCustomViewController 中
- (id) init
{
// there is an if statement here in real to choose another XIB if needed
// but I only display here the code that is called in my tests
self = [super initWithNibName:@"MyXIB" bundle:nil];
if (!self) return nil;
self.delegate = nil;
return self;
}
- (void) run
{
// do things with self.view
}
MyCustomViewController 继承 GenericWindowController
在 GenericWindowController 中
/*- (id) initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
if (!(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) return nil;
self.view.userInteractionEnabled = NO; // THE APP CRASHES HERE ! self.view is nil
...
return self;
}*/
// METHOD created following first answers : NOT CALLED
- (void) viewDidLoad
{
self.view.userInteractionEnabled = NO;
// and many other things done with self.view
}
MyXIB 的文件所有者设置为 MyCustomViewController,并且视图已连接。
所有文件都包含并签入到项目中。
GenericWindowController 旨在制作一些标准的东西。
MyCustomViewController 扩展了这些东西以使用 MyXIB 中设计的自定义视图。
为什么 self.view 在 GenericWindowController 中为零?
为什么不调用viewDidLoad?
【问题讨论】:
标签: iphone ios uiview uiviewcontroller viewdidload