removeFromSuperview doesn't work

后端 未结 3 849
灰色年华
灰色年华 2021-02-20 01:29

I need to be able to remove a button from a view and add a different one. My code looks like this:

-(void)UpdatePromoBanner:(NSString*)value{
    [button setTitl         


        
相关标签:
3条回答
  • 2021-02-20 01:42

    Oscar is right. You have to update the interface on the main thread. Figured I'd add in some code to help.

    Replace:

    [subView removeFromSuperview];
    

    With:

    [subView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO];
    

    And I think you should be good to go without changing anything else.

    0 讨论(0)
  • 2021-02-20 01:46

    You cannot update the UI using a secondary thread, whenever your thread is doing UI updates you must call the main thread.

    0 讨论(0)
  • 2021-02-20 01:58
    dispatch_async(dispatch_get_main_queue(), ^{
             [subView removeFromSuperview];
    });
    

    Remember update UI in main thread :)

    0 讨论(0)
提交回复
热议问题