我有一个转到 View Controller 的弹出窗口转场。单击单元格时,我想在 View Controller 中设置一些属性。我尝试使用 -prepareForSegue:
,但后来我意识到它没有所选单元格的范围。我知道我必须使用:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
委托(delegate)方法,但我不确定这将如何影响 popover segue。我必须以编程方式创建弹出窗口,还是有其他方法?
非常感谢!
~地毯嘶嘶声
最佳答案
使用 self.tableView.indexPathForSelectedRow
从表的数据源获取数据,例如支持表数据的数组。如果出于某种原因,您不想从数据源获取数据,那么 sender
是UITableViewCell
被点击以触发 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/