简体   繁体   English

iOS如何将选定的单元格值隔离到另一个视图控制器中

[英]iOS how to segue a selected cell value into another view controller

I have a Uitableview cell that has been successfully populated with dictionary array. 我有一个已成功用字典数组填充的Uitableview单元格。 Right now, i have difficulty passing the selected cell value to another view controller and display that value. 现在,我很难将选定的单元格值传递给另一个视图控制器并显示该值。

Here is my codes: 这是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


    NSLog(@"Tapped: %@",[[feeds objectAtIndex:indexPath.row]objectForKey:@"IncidentNumber"]);
    someProperty = [[feeds objectAtIndex:indexPath.row]objectForKey:@"IncidentNumber"];
     [self performSegueWithIdentifier:@"item" sender:self];

}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([[segue identifier] isEqualToString:@"yourSegue"])
    {

        DescriptionViewController *vc;
               vc = segue.destinationViewController;

                vc.item_pass = someProperty;
    }


}

您使用标识符执行segue,但稍后在prepareForSegue ,检查标识符为yourSegue的segue ...

Instead of implementing didSelectRowAtIndexPath connect the segue to the table view cell (rather than to the view controller). 代替实现didSelectRowAtIndexPath将segue连接到表视图单元格(而不是视图控制器)。

Then the selected cell is passed as sender parameter in prepareForSegue and you can get the index path with 然后,将所选单元格作为sender参数传递给prepareForSegue ,您可以使用以下命令获取索引路径

let selectedIndexPath = tableView.indexPathForCell(sender as! UITableViewCell)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS如何将一个数组转移到另一个视图控制器 - IOS how to segue an array to another view controller 如何将选定的collectionview单元格发送到另一个视图控制器(ios)? - How to send a selected collectionview cell to another view controller (ios)? 如何根据选定的单元格将segue推送到特定的View Controller? - How to push segue to specific View Controller depending on a selected cell? 自定义单元格中的选定行不会将完整数据从segue传递到另一个视图控制器 - selected row in custom cell doesn't pass complete data from segue to another view controller 模态视图控制器从自定义单元格选择问题中筛选-iOS 7 - Modal view controller segue from custom cell selection issue - iOS 7 如何将选定单元格中的数据传递给另一个视图控制器? - How to pass data in selected cell to another view controller? 如何在swift中将数组转换为另一个视图控制器? - How to segue array to another view controller in swift? 如何在选择时“取消” AVAudioSession到另一个视图控制器? - How To “Cancel” AVAudioSession on segue to another view controller? FSCalendar - 从选定的日期到另一个视图创建 segue controller - FSCalendar - create segue from day selected to another view controller 如何在segue中获取选定的表格视图单元格行? - How to get selected table view cell row in segue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM