Iphone Application:-My Application Crash

雨燕双飞 提交于 2019-11-29 18:04:28

This is because you are doing some UI changes on background thread. In ios you can not perform any UI changes on background thread , this will crash your app.

So you have to do your UI changes on main thread

[self performSelectorOnMainThread:@selector(doYourUIChanges:) withObject:nil waitUntilDone:YES];  

Or

dispatch_async(dispatch_get_main_queue(), ^{ 
//Your Task
});

or

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // background code
});

As mentioned by @Rajneesh071, UI changes must be performed on the main thread.

This can be done using:

[self performSelectorOnMainThread:@selector(doYourUIChanges:) withObject:nil waitUntilDone:YES];

Or if you want a section of in-line code to be performed on the main thread, use this:

dispatch_async(dispatch_get_main_queue(), ^{
    /* YOUR UI STUFF */
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!