I am making an iOS application and I have this method that runs in a thread, and i am also calling another method in this method, but at the point of execution of the second method, crashes the application, actually, i want to move to a new view after the second method succesfully executes.
我正在制作一个iOS应用程序,我有一个在线程中运行的方法,我也在这个方法中调用另一个方法,但是在执行第二个方法时,崩溃了应用程序,实际上,我想转移到第二种方法成功执行后的新视图。
Any help will be appreciated. request for the code may be welcome.
任何帮助将不胜感激。我们欢迎您提供代码请求。
1 个解决方案
#1
1
The UI is not thread safe. Hence, you should only update the UI from the main thread.
UI不是线程安全的。因此,您应该只从主线程更新UI。
To force code to run on the main thread, you can use a block like this in a thread or other block:
要强制代码在主线程上运行,可以在线程或其他块中使用这样的块:
dispatch_async(dispatch_get_main_queue(), ^{
// Update UI here
});
#1
1
The UI is not thread safe. Hence, you should only update the UI from the main thread.
UI不是线程安全的。因此,您应该只从主线程更新UI。
To force code to run on the main thread, you can use a block like this in a thread or other block:
要强制代码在主线程上运行,可以在线程或其他块中使用这样的块:
dispatch_async(dispatch_get_main_queue(), ^{
// Update UI here
});