Search code examples
iosobjective-cxcodeios7xcode5

Pass data between View Controllers - Storyboards segues


I'm not sure why, but it doesn't work in my project. I did exactly the same as in 1 million tutorials.

I have TableViewController with TableView, and simple ViewController for details.

And in detail ViewController in h file I declared:

@property (strong, nonatomic) NSString *testText;

then,in m file under @implementation:

@synthesize testText;

In TableViewController with list I have:

    //declared above: UIViewController *ticketDetailViewController = [segue destinationViewController];

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    NSString *destinationTitle = [[ticketArray objectAtIndex:[indexPath row]] pkey];
    [ticketDetailViewController setTitle:destinationTitle];

Everything, work great. Title is correct, so there must be connection. But, now I want pass other data… So I did testText property and I want to access from TableViewController, but I can't:/

Error says: Property 'testText' not found on object of type 'UIViewController *'

The really strange thing is.. during debugging, there is testText (like on the screen below):

enter image description here

Although when I want to implement it.. it's not found:

enter image description here

Anyone understands what is going on?


Solution

  • Change:

    UIViewController *ticketDetailViewController = [segue destinationViewController];
    

    to:

    TicketDetailViewController *ticketDetailViewController = (TicketDetailViewController *)[segue destinationViewController];
    

    so that the compiler knows what type of class you're using (and it can find/complete the appropriate properties).