[英]IOS Open New View controller Programatially
我需要以编程方式在我的应用程序上打开一个注册表单,该视图控制器是在Storyborad上创建的,带有Storybpard ID ViewControllerRegister
,而我用来打开该表单的代码是
RegistrationFormViewController *registerView = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerRegister"];
[self presentViewController:registerView animated:NO completion:nil];
但是,当我运行该应用程序时,出现了如下错误:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' *-[__ NSArrayM insertObject:atIndex:]:对象不能为零'*首先抛出调用栈:
1)确保故事板名称是“ Main”或其他。
2)检查您是否输入了正确的情节提要标识符。
最后,
3)有时Xcode无法使用self.storyboard
找到故事板。 尝试使用真实名称(例如,
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
RegistrationFormViewController *registrationFormViewController = [storyBoard instantiateViewControllerWithIdentifier:@"RegistrationFormViewController"];
[self presentViewController:registrationFormViewController animated:YES completion:nil];
[__NSArrayM insertObject:atIndex:]:对象不能为nil,错误提示在代码中查找任何显示“
insertObject:atIndex:
”的行。 您要插入的对象显然为nil。
在添加任何对象之前,请确保已初始化名为XXXX的数组。
NSMutableArray *xxx=[[NSMutableArray alloc]init];
并停止向其中添加任何nil对象...
if(str) //or if(str != nil) or if(str.length>0)
{
//add the str into xxx array.
}
else
{
//add the empty value to your xxx array
}
您的代码中以编程方式加载视图控制器没有问题。 您必须使用断点检查是否在打开控制器中调用了viewDidLoad
方法。 如果正在调用它,那么一切都很好,您需要检查打开控制器的生命周期方法中正在执行的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.