Search code examples
iossegueuistoryboardsegue

How to use prepareSegue method in storyboard?


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
       NSIndexPath *indexPath = [self.myTableView indexPathForSelectedRow];
       ThirdViewController *destViewController = segue.destinationViewController;
        segue.destinationViewController displayTitlesArray = [[NSArray alloc]initWithObjects:@"first ",@"second",@"Third", nil ];}

display titles array is array in next view controller.But here I'm getting error.How can i pass the data to next view controller using segue.destinationViewController object.


Solution

  • - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
           NSIndexPath *indexPath = [self.myTableView indexPathForSelectedRow];
           ThirdViewController *destViewController = (ThirdViewController  *)segue.destinationViewController;
           destViewController.displayTitlesArray = [[NSArray alloc]initWithObjects:@"first ",@"second",@"Third", nil ];}