I am trying to pass a variable (tutorID) to another view controller (TimetableTableViewController) but when the code runs the app crashes giving and error message: Thread 1: signal SIGABRT.

I have this inside my TimetableTableViewController.h (the view I'm passing the variable to):

@property (nonatomic, strong) NSString *currentTutorID;

And this inside my prepareForSegue method in the view controller I'm sending the variable from:

NSString *tutorID = @"1";

TimetableTableViewController * timetableTableViewController = [segue destinationViewController];
timetableTableViewController.currentTutorID = tutorID;

If anyone could help me fix this error or give me another way, thank you.

EDIT

The segue is leading to a NavigationViewController so thats why it's crashing. Does anyone know how I can pass the variable to TimetableTableViewController instead of the NavagationViewController.

有帮助吗?

解决方案

Strange that you are getting SIGABRT, it should say that your controller not responding to selector tutorID.

Use [segue.destinationViewController topViewController] to get root controller from navigation controller that you want to present.

其他提示

So the problem is your segue is going in NavigationViewController and TimetableTableViewController is root view controller of it.

In this case [segue destinationViewController] will return NavigationViewController not TimetableTableViewController.

You can try this.

NavigationViewController * nav = [segue destinationViewController];
TimetableTableViewController * timetableTableViewController = nav[0];
timetableTableViewController.currentTutorID = tutorID;

Try this and tell me what you are getting.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top