Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.view setNeedsDisplay and self.view setNeedsLayout are not working

Tags:

xcode

ios

I have a main view controller showing on the screen and a class (delegate) running in the background getting positions. When I get the result I call the delegate method in the view controller to update the label on the screen. I tried several ways but still no update to the screen.

Here is the method:

-(void) updateDisplay
{

    NSLog(@"%@",myPosition.currentArea);
    _area.text = [NSString stringWithFormat:@"area = %@",myPosition.currentShopArea];


    //[self.view performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
    [self.view setNeedsDisplay];
    //[self.view setNeedsLayout];
}

I check the console, it displays the correct area but on the screen still showing null. I tried all three ways (commented out above) but none of those update the screen.

like image 238
Ali Avatar asked Dec 28 '25 14:12

Ali


1 Answers

You could try 2 things:

  1. calling updateDisplay on the main thread:

    [delegate performSelectorOnMainThread:@selector(updateDisplay) withObject:nil waitUntilDone:YES];
    

    in the end, it is accessing UIKit, so better doing it right;

  2. if that does not help, try with:

    [_area setNeedsDisplay];
    

    In this case also, if would be advisable to call the method on the main thread.

like image 153
sergio Avatar answered Dec 31 '25 04:12

sergio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!