gpt4 book ai didi

iphone - 访问 UIViewController 时的 SIGABRT

转载 作者:行者123 更新时间:2023-11-29 13:02:10 24 4
gpt4 key购买 nike

我习惯于从 Storyboard文件或 xib 文件加载 ViewController,所以当我第一次尝试在代码中加载时:

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”

假设我的 Storyboard 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];
}

感谢您的帮助!

最佳答案

没关系,原来错误是在 [self displayInfo:currentIndex] ViewDidLoad 的最后一行。我错误地认为在实例化 ViewController 时安全地调用了 viewDidLoad。当我调用 self.view 时,它会在很久以后调用。

<_< 延迟初始化,对吧?

关于iphone - 访问 UIViewController 时的 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19512212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com