iOS 7表视图didSelectRowAtIndexPath

时间:2014-05-26 01:04:36

标签: ios uitableview sdk

我有这个问题,当我点击我的手机时,我的应用程序崩溃......

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
   detailViewController.title = [[colleges objectAtIndex:indexPath.row] objectForKey:@"name"];
   detailViewController.college = [colleges objectAtIndex:indexPath.row];
   [self.navigationController pushViewController:detailViewController animated:YES]; 
}

它说

"2014-05-25 21:24:55.783 CollegeSearchPro[1450:60b] (
0   CollegeSearchPro                    0x0000000100076578 -[ViewController tableView:didSelectRowAtIndexPath:] + 604
1   UIKit                               0x00000001876dff9c <redacted> + 1264
2   UIKit                               0x00000001877a1d0c <redacted> + 240
3   UIKit                               0x0000000187636fb4 <redacted> + 356
4   UIKit                               0x00000001875a1d88 <redacted> + 504
5   CoreFoundation                      0x000000018469b7e0 <redacted> + 32
6   CoreFoundation                      0x0000000184698a68 <redacted> + 372
7   CoreFoundation                      0x0000000184698df4 <redacted> + 764
8   CoreFoundation                      0x00000001845d9b38 CFRunLoopRunSpecific + 452
9   GraphicsServices                    0x0000000189fff830 GSEventRunModal + 168
10  UIKit                               0x00000001876180e8 UIApplicationMain + 1156
11  CollegeSearchPro                    0x0000000100076a3c main + 116
12  libdyld.dylib                       0x0000000190c43aa0 <redacted> + 4
)

2014-05-25 21:24:55.792 CollegeSearchPro[1450:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/A9F4E1C1-FEBB-4093-9E96-B003FBAB48B3/CollegeSearchPro.app> (loaded)' with name 'DetailViewController''
*** First throw call stack:
(0x1846db09c 0x190659d78 0x1846dafdc 0x187958c98 0x1878a7abc 0x1875b00d8 0x1875b0044 0x18775d894 0x187668794 0x187668564 0x1876684e4 0x1875aad78 0x1871a70cc 0x1871a1c94 0x1871a1b4c 0x1871a13d4 0x1871a1178 0x18719aa30 0x18469b7e0 0x184698a68 0x184698df4 0x1845d9b38 0x189fff830 0x1876180e8 0x100076a3c 0x190c43aa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) "

2 个答案:

答案 0 :(得分:1)

如果您使用的是storyboard,请使用nib名称删除init

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[self performSegueWithIdentifier:@"YourSegueID" sender:self.view];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

 if ([segue.identifier isEqualToString:@"YourSegueID"])
 {
    DetailViewController *detailViewController= segue.destinationViewController;
    detailViewController.title = [[colleges objectAtIndex:indexPath.row] objectForKey:@"name"];
    detailViewController.college = [colleges objectAtIndex:indexPath.row];

 }
}

如果你正在使用xib,那么交叉检查DetailViewController的xib。可能是你的xib名称有一些拼写错误。

答案 1 :(得分:1)

//If you are using xib files then use this code

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
   detailViewController.title = [[colleges objectAtIndex:indexPath.row] objectForKey:@"name"];
   detailViewController.college = [colleges objectAtIndex:indexPath.row];
   [self.navigationController pushViewController:detailViewController animated:YES]; 
}

确保DetailViewController.xib在您的应用包中

//If you are using storyboards then use this code

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   DetailViewController *detailViewController=[self.storyboard instantiateViewControllerWithIdentifier:@"detailViewController"];
   detailViewController.title = [[colleges objectAtIndex:indexPath.row] objectForKey:@"name"];
   detailViewController.college = [colleges objectAtIndex:indexPath.row];
   [self.navigationController pushViewController:detailViewController animated:YES]; 
}