2

我有一个 UItableViewController。在这个类中有以下方法,我试图在其中启动另一个 UIViewController。我尝试使用 segue 连接两者并给它一个标识符,然后使用这个版本:

- (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 无效???有人可以帮忙吗,我很困惑。

4

1 回答 1

3

我不明白您到底面临什么问题,但我想告诉您,由于您首先使用的是 uitableview,请将其单元连接到新的视图控制器并选择“推送”segue 方法。完成此操作后,将以下代码添加到应用程序中,而不是用户didselectrowatindexpath方法。

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

    /*选择行时,SEGUE将创建详细信息控制器作为目的地。将详细视图控制器的详细信息项设置为与所选行关联的项。*/ if ([[segue identifier] isEqualToString:@"Showcategorydetails"]) {

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

    } }

于 2011-12-30T13:08:22.917 回答