【问题标题】:How to use prepareForSegue for multiple Tableview Controllers如何为多个 Tableview 控制器使用 prepareForSegue
【发布时间】:2015-02-07 06:54:14
【问题描述】:

我有三个表视图 A,B,C 。视图流程是这样的:

表A,点击一行--->表B,点击一行----表C

我正在使用以下方法将数据从主视图A发送到详细视图B。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetailFinal"]) {

    NSIndexPath *indexPath = [self->ListView_A indexPathForSelectedRow];
    DetailView_B *destViewController = segue.destinationViewController;

    destViewController.detailStatements = [dataArray objectAtIndex:indexPath.row];

}
}

我再次使用相同的方法将数据从 detailView_B 发送到 moreDetailView_C

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetailFinal"]) {

    NSIndexPath *indexPath = [self->DetailView_B indexPathForSelectedRow];
    More_DetailView_C *destViewController = segue.destinationViewController;

    destViewController.detailStatements = [dataArray objectAtIndex:indexPath.row];

}
}

我使用的是模态序列而不是推送。问题是,当我从表 A 转到表 B 时,我看到表 B 中的数据。

但是当我从表 C 回到表 B 时,我没有看到表 B 中的任何数据。

表B中的视图确实加载方法是:

- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"the name is %@",detailStatements.name);
// here when I come from table A, name is not null

//but when I come from table C,name is null.

}

是否可以对所有 3 个表视图使用通用的 segue 标识符?

请告诉我可能的处理方法?

【问题讨论】:

  • 你能告诉我们你从C带到B的代码吗?C-->B和B-->A。我认为当您从 C 返回到 B 时,您必须创建 tableView B 的新实例。
  • 你如何从 C 到 B?
  • 通过顶部导航栏中的导航按钮。我没有使用任何代码。
  • 我只是 ctrl 将表 C 中的导航按钮拖到表 B 并使其成为模态搜索!!!我从 B 到 A 做了同样的事情。

标签: ios objective-c uitableview


【解决方案1】:

从你的 cmets 你需要一个 unwind segue 而不是你用来倒退的正常 segue。

这可能有助于Storyboard: Control-drag from a bar button to the Exit item

或者向按钮添加一个动作来简单地关闭视图控制器。

【讨论】:

  • 我对按钮使用了一个动作来关闭视图控制器。很高兴它就像一个魅力!!!!谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
相关资源
最近更新 更多