SetNeedsDisplay not working

前端 未结 2 1283
故里飘歌
故里飘歌 2021-02-14 13:59

I saw many threads related to this issue, but none addresses my case (I think).

My case should be simple, I have a Custom UIView in my controller, from my c

相关标签:
2条回答
  • 2021-02-14 14:28

    I think the correct way to use it is:

    [self setNeedsDisplay:YES]; 
    

    Although I always have problems to get that working :(

    0 讨论(0)
  • 2021-02-14 14:29

    After alot of testing, I saw something related to threads and the fact setNeedsDisplay should only be called in the mainThread...besides I never started a separeted thread in this classes, the class that raised the Notification was in a secondary thread...and aparently this was causing the issue...

    to Solve it I just forced setNeedsDisplay to be called in the main thread..

    dispatch_async(dispatch_get_main_queue(), ^{
                [self setNeedsDisplay];  
    });
    

    Swift 3:

    DispatchQueue.main.async { [weak self] in
        self?.setNeedsDisplay()
    }
    
    0 讨论(0)
提交回复
热议问题