在 TableView 中使用多个详细视图 [英] Using multiple detail views with TableView

查看:22
本文介绍了在 TableView 中使用多个详细视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的标签栏应用程序中实现一个表格视图页面.我已经成功制作了一个包含数据的表视图,我希望这能带我进入详细视图.但是,我希望每个单元格都有单独的细节视图,以允许我使用 UI 创建更详细的细节视图.我已经给了 Seque 的唯一 ID 来尝试这样做.

Im trying to implement a table view page within my tabbed bar application. I have successfully made a table view containing data, and I want this to take me to a detail view. However I want separate detail views for each Cell, to allow me to create more detailed detail views using the UI. I have given the Seque's unique IDs to try and do this.

目前我每次按下按钮都会崩溃,将我带到 main.m

Currently it crashed every time I press the button, taking me to main.m

这是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            [self performSegueWithIdentifier:@"showDetail1" sender:self];
            break;
        case 1:
            [self performSegueWithIdentifier:@"showDetail2" sender:self];
            break;
        case 2:
            [self performSegueWithIdentifier:@"showDetail3" sender:self];
            break;
        case 3:
            [self performSegueWithIdentifier:@"showDetail4" sender:self];
            break;
        default:
            break;
     }
}

我得到的例外是:

由于未捕获的异常‘NSGenericException’而终止应用程序,原因:‘找不到segue‘showDetail2’的导航控制器.只有当源控制器由UINavigationController的实例管理时才能使用推送segue."

"Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'showDetail2'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'"

谢谢!

推荐答案

添加 tableViewViewController 应该是 NavigationController 的一部分.ViewController 只能被推送,如果它是 NavigationController 的一部分.或者尝试使用 Present Segue.

The ViewController where you have added your tableView, should be a part of a NavigationController. A ViewController can only be pushed if it is a part of NavigationController. Else try using Present Segue.

解决方案 1:

让你现在的 ViewController 加入你的 tableView 成为 NavigationController

Make your present ViewController in which you have added your tableView a part of NavigationController

如果您使用的是 StoryBoard,请选择您添加了 tableView 的 ViewController.选择控制器后,选择 Editor\Embed In\Navigation Controller

If you are using StoryBoard, then select your ViewController in which you have added the tableView. With the Controller selected, choose Editor\Embed In\Navigation Controller

解决方案 2:

如果您不想使用Navigation/Push 设计,那么您可以呈现ViewController.为此,您必须使用 Present Segues.

If you do not want to use Navigation/Push design then you can present the ViewController. For that you have to use Present Segues.

这篇关于在 TableView 中使用多个详细视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆