单击每一行将引导您进入另一个视图控制器
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if( indexPath.row == 0 ){
titleController = [[TitleFundraiserController alloc] initWithNibName:@"TitleFundraiserController" bundle:nil];
[self.navigationController presentViewController:titleController animated:YES completion:nil];
}
if( indexPath.row == 1 ) {
recipientController = [[RecipientController alloc] initWithNibName:@"RecipientController" bundle:nil];
[self.navigationController presentViewController:recipientController animated:YES completion:nil];
}
if( indexPath.row == 2 ) {
fundController = [[FundingController alloc] initWithNibName:@"FundingController" bundle:nil];
[self.navigationController presentViewController:recipientController animated:YES completion:nil];
}
if( indexPath.row == 3 ) {
locationController = [[LocationController alloc] initWithNibName:@"LocationController" bundle:nil];
[self.navigationController presentViewController:locationController animated:YES completion:nil];
}
}
但是,有时我从控制台收到此错误,我的程序崩溃
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Application tried to present a nil modal view controller on target <UINavigationController: 0x7c7a340>.'
我不知道为什么这么说。
如果您之前遇到此问题,请提供帮助。
由于
答案 0 :(得分:1)
我唯一看错的代码是在presentViewController之后,你还需要释放变量:
if ( indexPath.row == 0 ) {
titleController = [[TitleFundraiserController alloc] initWithNibName:@"TitleFundraiserController" bundle:nil];
[self.navigationController presentViewController:titleController animated:YES completion:nil];
[titleController release];
}
我没有看到任何原因导致您随机出现错误,是不是总是在同一行?发生的事情是ViewController
没有从笔尖加载,因此返回nil
。
答案 1 :(得分:1)
当您提交recipientController
if (indexPath.row == 2)
声明中提出了fundController
以下是更正后的代码:
if( indexPath.row == 2 ) {
fundController = [[FundingController alloc] initWithNibName:@"FundingController" bundle:nil];
[self.navigationController presentViewController:fundController animated:YES completion:nil];
}
您收到该错误,因为recipientController
在此处展示时将为零