[英]Passing Variables between View Controllers - Thread 1: signal SIGABRT
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
. 我正在尝试将变量( tutorID
)传递给另一个视图控制器( TimetableTableViewController
),但是当代码运行时,应用程序崩溃并给出错误消息: Thread 1: signal SIGABRT
。
I have this inside my TimetableTableViewController.h
(the view I'm passing the variable to): 我在TimetableTableViewController.h
(将变量传递到的视图中)中包含以下内容:
@property (nonatomic, strong) NSString *currentTutorID;
And this inside my prepareForSegue
method in the view controller I'm sending the variable from: 而这在视图控制器的prepareForSegue
方法中,我从发送变量:
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. 这个问题导致了NavigationViewController
所以这就是它崩溃的原因。 Does anyone know how I can pass the variable to TimetableTableViewController
instead of the NavagationViewController
. 有谁知道我如何将变量传递给TimetableTableViewController
而不是NavagationViewController
。
Strange that you are getting SIGABRT, it should say that your controller not responding to selector tutorID
. 奇怪的是,您正在获取SIGABRT,应该说您的控制器没有响应选择器tutorID
。
Use [segue.destinationViewController topViewController]
to get root controller from navigation controller that you want to present. 使用[segue.destinationViewController topViewController]
从要显示的导航控制器中获取根控制器。
So the problem is your segue is going in NavigationViewController and TimetableTableViewController is root view controller of it. 所以问题是您的segue正在NavigationViewController中,而TimetableTableViewController是它的根视图控制器。
In this case [segue destinationViewController] will return NavigationViewController not TimetableTableViewController. 在这种情况下,[segue destinationViewController]将返回NavigationViewController而不是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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.