我有这个级联:
应用程序中的某处
- (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
不叫?