我习惯于从故事板文件或 xib 文件加载 ViewControllers,所以当我第一次尝试在代码中加载一个时:
UIStoryboard *storyboard = self.storyboard;
ProfileViewController *profViewController = [storyboard instantiateViewControllerWithIdentifier:@"ProfileView"];
NSLog(@"Self View Frame: %@", NSStringFromCGSize(self.view.frame.size));
NSLog(@"ProfViewCont Frame: %@", NSStringFromCGSize(profViewController.view.frame.size));
我收到以下错误:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSPlaceholderMutableString initWithString:]: nil argument”
假设我的故事板 xib 正确加载,我需要做些什么不同的事情?这是 viewDidLoad:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// add subviews
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = YES;
[UIView beginAnimations:nil context:nil];
[self.view setFrame:CGRectMake(0, 480, 320, 480)];
[UIView setAnimationDuration:0.75f];
[self.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
// Sort stat bars top to bottom (HP == 0):
statBars = [statBars
sortedArrayUsingComparator:^NSComparisonResult(id label1, id label2)
{
if ([label1 frame].origin.y < [label2 frame].origin.y)
return NSOrderedAscending;
else
return NSOrderedDescending;
}];
// Sort types left to right:
types = [types
sortedArrayUsingComparator:^NSComparisonResult(id label1, id label2)
{
if ([label1 frame].origin.x < [label2 frame].origin.x)
return NSOrderedAscending;
else
return NSOrderedDescending;
}];
[self displayInfo:currentIndex];
}
谢谢你的帮助!