ios pass values during a segue to another view

后端 未结 5 769
暗喜
暗喜 2020-12-24 12:15

Trying to do something I\'ve seen documented in a lot of places, but can\'t seem to manage. I\'m trying to pass data from one view to another during a segue.

Here\'s

5条回答
  •  孤城傲影
    2020-12-24 12:57

    you can achieve it by doing this: first pass the value you want to send to the destination controller here:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
         [self performSegueWithIdentifier:@"segueToLocation" sender:the object you want to pass];
    }
    

    then get the object here

    - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString: @"segueToLocation"]) {    
             DetailViewController *dest = (DetailViewController *)[segue destinationViewController];
             //the sender is what you pass into the previous method
             dest.target=sender
        }
    }
    

提交回复
热议问题