【问题标题】:Passing cell title to detail view using storyboard使用情节提要将单元格标题传递给详细视图
【发布时间】:2013-08-08 13:03:02
【问题描述】:

我正在尝试使用情节提要将选定的单元格标题传递给 deatil 视图控制器,但这并不容易,因为单元格的选择。

我不知道如何确定目前选择了哪一个并将其标题传递给详细视图属性。

我想我必须先使用prepareForSegue:sender(这是我得到所有东西的地方)然后在tableView:didSelectRowAtIndexPath 中调用performSegueWithIdentifier:sender:,对吧?

这是我的示例:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"projectDetailsSegue"]) {
        AlbumViewController *destinationView = [segue destinationViewController];
        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:selectedRowIndex];
        destinationView.projectTitle = selectedCell.textLabel.text;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"projectDetailsSegue" sender:self];
}

当我在详细视图控制器中记录 projectTitle 时,它​​显示 (null)

这是我的问题 - 我怎样才能做到这一点并将这个标题传递给另一个视图控制器以使用它?

【问题讨论】:

  • 请看这个链接:appcoda.com/…希望对你有帮助。
  • 这就是我要找的。可惜没早点发现!谢谢!

标签: ios storyboard uitableview segue


【解决方案1】:

找到解决方案here。这是我正确的prepareForSegue:sender: 方法体:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"projectDetailsSegue"]) {
        AlbumViewController *destinationView = [segue destinationViewController];
        UITableViewCell *selectedCell = (UITableViewCell *)sender;
        destinationView.projectTitle = selectedCell.textLabel.text;
    }
}

【讨论】:

    猜你喜欢
    • 2012-12-18
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    相关资源
    最近更新 更多