3D Touch Peek and Pop from UITableViewCell how to hand over data to other UIViewController?

前端 未结 3 512
天命终不由人
天命终不由人 2020-12-14 11:59

my app stores different attributes in Core Data objects. They are all shown in a UITableView, if you click a cell, a DetailView is shown. the usual stuff like in the Master-

3条回答
  •  盖世英雄少女心
    2020-12-14 12:32

    If you are using storyboard segues from the cell to the new view controller, the sender is the table view cell.

    So you could implement prepareForSegue: as such:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if ([sender isKindOfClass:[UITableViewCell class]]) {
    
            UITableViewCell *cell = sender;
            NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
            id viewController = segue.destinationViewController;
    
            // Get your data object
            // Pass it to the new view controller
        }
    }
    

提交回复
热议问题