1

单击的每一行都会将您带到另一个视图控制器

-(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>.'

我不知道为什么这么说。

如果您以前遇到过此问题,请提供帮助。

谢谢

4

2 回答 2

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

于 2012-07-16T18:46:22.660 回答
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在此处展示时将为零

于 2012-07-16T19:01:59.770 回答