我有一个 UIViewController 和一个自定义的 init 方法,如下所示:
- (id)initWithFrame:(CGRect)frame_ customObject:(CustomObject *)object_ {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self = [super initWithNibName:@"ArtistViewController_iPad" bundle:nil];
} else {
self = [super initWithNibName:@"ArtistViewController" bundle:nil];
}
[self.view setFrame:frame_];
self.customObject = object_;
return self;
}
但是当 [self.view setFrame:frame_]; 被调用,它在日志中崩溃:
(null) libc++abi.dylib: 终止调用抛出异常
这就是我从另一个 UIViewController 分配 UIViewController 的方式:
CGRect frame = self.view.frame;
artistViewController = [[ArtistViewController alloc] initWithFrame:frame customObject:anObject];
框架存在。自我存在于 [super initWithNibName:bundle];
但 self.view 似乎不存在。nib 文件存在并且连接了它们的视图出口。
为什么会这样?