Iphone Application:-My Application Crash

后端 未结 2 605
小蘑菇
小蘑菇 2020-12-22 08:45

I make one custom cell class like this.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

self = [super initWith         


        
相关标签:
2条回答
  • 2020-12-22 08:56

    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 */
    });
    
    0 讨论(0)
  • 2020-12-22 08:58

    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
    });
    
    0 讨论(0)
提交回复
热议问题