Passing data between two controllers using storyboards

前端 未结 4 1000
时光取名叫无心
时光取名叫无心 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:37

    You need to understand that performSegueWithIdentifier:sender: creates a new instance of view controller. So the ListsViewController that you have created is not the being displayed on the screen.

    You need to override `prepareForSegue:sender:

    - (void)showList:(Subject *)subject animated:(BOOL)animated 
    {
      [self performSegueWithIdentifier:@"showDetail" sender:self];
    }
    
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"showDetail"]) {
            ListsViewController *controller = (ListsViewController *)segue.destinationViewController;
        controller.subject = self.subject;
    }
    

提交回复
热议问题