Passing data between two controllers using storyboards

前端 未结 4 970
时光取名叫无心
时光取名叫无心 2021-01-16 04:53

I am trying to pass data from one UITableViewController to another. This is my code in the initial view controller:

- (void)tableView:(UITableVi         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 05:45

    That's good, but now you need to add this:

    First instead of:

    [self performSegueWithIdentifier:@"showDetail" sender:self];
    

    You need to send the object:

    [self performSegueWithIdentifier:@"showDetail" sender:subject];
    

    Add a property in your ListsViewController.h:

    @property (nonatomic, strong) Subject * subjectSegue;
    

    And now in your first view controller:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"showDetail"]) {
            ListsViewController * lists = (ListsViewController *)[segue destinationViewController];
            lists.subjectSegue = sender;
    }
    

提交回复
热议问题