ios - Segue 没有将数据传递到目的地

标签 ios objective-c xcode ios6 uistoryboardsegue

我有两个 TableView Controller ,一个包含美国所有州,另一个显示所选州的数据列表。我已经从 View Controller (不是单元格)在我的主 Storyboard 中设置了一个 segue,并给它一个标识符。由于超出本文范围的原因,我需要在不使用 prepareForSegue 方法的情况下以编程方式执行 segue。

源 TableView Controller (AllStatesTableViewController)需要在tableview的didSelectRowAtIndexPath方法中执行segue。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    stateID = [statesDict objectForKey:cell.textLabel.text];

    DetailTableViewController *destination = [[DetailTableViewController alloc] init];

    stateGauges = [[GaugeList alloc] initWithStateIdentifier:stateID andType:nil];
    // at this point stateGauges is NOT nil

    [destination setStateGauges:stateGauges];

    [self performSegueWithIdentifier:@"sgShowStateDetail" sender:self];
}

segue 按预期执行,因为它导航到目的地,但 stateGauges 在目的地 TableView Controller 中为 nil。它在源 TableView Controller 中不是零。 stateGuages 被声明为 DetailTableViewController 中的一个属性。显然我做错了什么。有什么建议吗?

谢谢! V

最佳答案

在你的 Storyboard上,你需要选择从你的单元格中推送你的 segue。

enter image description here enter image description here

并使用您的 prepareForSegue 传递数据:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
    if ([segue.identifier isEqualToString:@"showDetail"]) 
    {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        DetailTableViewController *detailTableViewController = segue.destinationViewController;

        // Pass data here
        destViewController.stateGauges = stateGauges;
    }
}

看看here了解更多信息

关于ios - Segue 没有将数据传递到目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19364300/

相关文章:

ios - 与 Watch Connectivity 的 updateApplicationContext 共享访问 token 是否安全?

objective-c - 生成DSYM文件: dsymutil fails with exit code 11

iphone - 创建带有按钮的自定义调出 View

swift - SpriteKit - 为整个场景添加模糊

ios - 为 iOS React-Native 项目设置 Fbsdk 框架

ios - ./fruitstrap -d -b 之后的 fruitstrap 断言失败

c# - Xamarin Forms IOS - MKUserTrackingButton 位置

ios - UITableView didselectrowatindexpath 没有被调用

ios - 如何使用自动布局从 IB 访问正确的宽度值

xcode - iOS 7背景音效