2011-12-30 64 views
2

我有一个UItableViewController。在这个类里面有以下方法,我试图启动另一个UIViewController。我试图用一个SEGUE连接两个并赋予它一个识别码,然后使用这个版本:从UITableViewController启动UIViewcontroller崩溃应用程序

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
    NSLog(@"About to launch MyDetail View controller"); 
    [self performSegueWithIdentifier:@"myDetailSegue" sender:self]; 
} 

没有工作,应用程序冻结和我的main.m文件的消息如下:“”线程1接收到的信号SIGABRT”

所以后来删除了SEGUE并试图实例化的UIViewController如下,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"About to launch my Detail View controller"); 
    UIStoryboard *sboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil]; 
    UIViewController *myDetailVC = [sboard instantiateViewControllerWithIdentifier:@"myDetailVC"]; 
    [self.navigationController pushViewController:myDetailVC animated:YES]; 
} 

它的工作。但我现在感到困惑。为什么会产生UIStoryboard工作方式和SEGUE不是? 有人请帮忙, 我很困惑。

+0

请张贴崩溃日志。 – Ilanchezhian 2011-12-30 05:32:11

+0

哪里可以找到? – banditKing 2011-12-30 17:30:38

回答

3

我不明白你面对的究竟是什么问题,但我想告诉你,因为你先使用uitableview,请将其单元连接到新的视图控制器,并选择'推'赛格方法。完成此操作后,在您的应用程序中添加以下代码,而不是在用户didselectrowatindexpath方法中。

  • (无效)prepareForSegue:(UIStoryboardSegue *)赛格瑞发件人:(ID)发送方{

    /* 当选择一排,所述SEGUE创建细节视图控制器作为目标。 将详细视图控制器的详细项目设置为与选定行关联的项目。 */ 如果([[赛格瑞标识符] isEqualToString:@ “Showcategorydetails”]){

    NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow]; 
    CategoryDetailsController *detailViewController = [segue destinationViewController]; 
    detailViewController.category_title = [maincategories_array objectAtIndex:selectedRowIndex.row]; 
    

    } }

+0

谢谢。问题在于目的地Viewcontroller崩溃,因为插座连接都搞砸了。我在另一个View Controller的故事板上复制了ViewController,并复制了插座连接。所以ViewController的这个副本被连接到旧的Viewcontroller的插座。一旦这个问题得到解决,我很乐意去。 谢谢 – banditKing 2012-01-01 20:44:40