ios - 使用 segue 传递 tableviewcell 数据?

标签 ios objective-c uitableview

我有一个转到 View Controller 的弹出窗口转场。单击单元格时,我想在 View Controller 中设置一些属性。我尝试使用 -prepareForSegue:,但后来我意识到它没有所选单元格的范围。我知道我必须使用:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 委托(delegate)方法,但我不确定这将如何影响 popover segue。我必须以编程方式创建弹出窗口,还是有其他方法?

非常感谢!

~地毯嘶嘶声

最佳答案

使用 self.tableView.indexPathForSelectedRow从表的数据源获取数据,例如支持表数据的数组。如果出于某种原因,您不想从数据源获取数据,那么 senderUITableViewCell被点击以触发 segue。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"YourSegueID"]) {
        YourDestinationViewControllerClass* destinationController = segue.destinationViewController;
        destinationController.somePublicProperty = self.yourTablesDataSourceArray[self.tableView.indexPathForSelectedRow.row];

        UITableViewCell *cell = (UITableViewCell *)sender;
        destinationController.someOtherPublicProperty = cell.textLabel.text;
    }
}

关于ios - 使用 segue 传递 tableviewcell 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777318/

相关文章:

objective-c - 以编程方式在另一个桌面(空间)中打开 NSWindow

ios - CustomUITableViewCell 未在所有模拟器上显示 subview

ios - 为 SKSpriteNode 生成位置

ios - SpriteKit - 多个对象的接触检测

ios - 如何找到 Bridging-Header.h 的路径 - Swift,Xcode

ios - iOS 7完整的UINavigationBar透明度

iphone - UIATableView 始终命名为 "Empty list"

objective-c - 防止父 View UIGestureRecongnizer 在 UITableVIew subview 中执行

ios - UIViewController 中 present() 函数的 Swift 协议(protocol)

ios - 应用程序更新/重新部署后无法访问文件 (ios)