uitableview - TableView 多段

标签 uitableview pushviewcontroller

您好,我正在 Storyboard中使用 TableView 创建一个应用程序,到目前为止,我能够填充表,我将其设置为制作 4 个单元格,并从每个单元格推送到相同的 View Controller ,但我希望能够要做的是每个单元格将我带到一个新的 View Controller

这是迄今为止我所掌握的内容,如果您能为我指明正确的方向,如何做到这一点,那就太好了

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

if ([[segue identifier] isEqualToString:@"ShowSimpleDetails"]) {
    SimpleTutorialsViewController *detailViewController = [segue destinationViewController];

    NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

    int row = [myIndexPath row];
    detailViewController.simpleDetailModal = @[_simpleTitle[row], _simpleDescription[row], _simpleImages[row]];
   }
}

最佳答案

您可以在 Storyboard或代码中执行此操作:

在 Storyboard

您可以绘制从单元格到目标 View Controller 的 Segue,并在属性检查器中为该 Segue 提供唯一标识符。您可以使用它通过拥有多个单元原型(prototype)来连接到多个目的地,每个原型(prototype)都有自己的连接。

在代码中

要在代码中执行此操作,您需要从 View Controller (而不是单元格)到每个目的地绘制一条 Segue,并为每个 Segue 提供唯一的标识符。然后在 didSelectRowAtIndexPath 中,您将根据所选索引路径决定所需的目的地,并执行如下的 segue

NSString *segueIdentifier = @"someIdentifier";//or whatever logic you need to determined the appropriate identifier
id sender = self;//or whatever object you want to be the sender
[self performSegueWithIdentifier:segueIdentifier sender:sender];

准备Segue

prepareForSegue 中,每个可能的 segue 标识符都有一个条件 block :

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"oneSegueIdentifier"]) {
        //preparation
    } else if ([[segue identifier] isEqualToString:@"anotherSegueIdentifier"]) {
        //other preparation
    }
}

关于uitableview - TableView 多段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18043743/

相关文章:

ios - 在单元格出列并重新加载之前,tableviewcell 中的属性字符串不显示粗体文本

iphone - 调用 reloadRowsAtIndexPaths 删除 tableView contentOffset

ios - 选择 UITableView 中的所有行,并在数组中附加标签

ios - 多次推送和弹出动画后导航栏的奇怪行为 NO。 IOS 7

ios - 推送 View 时更改 iOS 应用程序的背景颜色

ios - 快速加载更多数据会重复已经存在的单元格

ios - 单例 UIViewController

ios - Watchkit,dismissController 函数

ios - UINavigationController pushviewcontroller 内存管理

json - 我们怎样才能在firstVC中获取secondVC json值而不需要在swift中转到secondVC