IOS GUI Update

I use setNeedsDisplay in my GUI, but sometimes the update fails. I use UIPageControllViewevery page has a UIScrollViewc UIViewinside.

I have the following pipeline:

1) the application comes from the background - applicationWillEnterForeground

2) start downloading data from the server

2.1) after the data loading is completed, the trigger selector

3) use dispatch_asyncwith dispatch_get_main_queue()to fill shortcuts, images, etc. new data

3.1) call setNeedsDisplayto view (also tried scrolling and page control)

The problem is that step 3.1 is called, but the apper changes from time to time. If I change pages, the update is performed, and I can see the new data (so that the download works correctly). But without manually turning the page, there is no update.

Any help?

Edit: code from step 3 and 3.1 (the _needRefresh variables specified in the comments have been removed)

 -(void)FillData {
    dispatch_async(dispatch_get_main_queue(), ^{

    NSString *stateID = [DataManager  ConvertStateToStringFromID:_activeCity.actual_weather.state];

    if ([_activeCity.actual_weather.is_night boolValue] == YES)
    {
          self.contentBgImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"bg_%@_noc", [_bgs objectForKey:stateID]]];

        if (_isNight == NO)
        {
            _bgTransparencyInited = NO;
        }

        _isNight = YES;

    }
    else
    {
        self.contentBgImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"bg_%@", [_bgs objectForKey:stateID]]];

        if (_isNight == YES)
        {
            _bgTransparencyInited = NO;
        }

        _isNight = NO;

    }
    [self.contentBgImage setNeedsDisplay]; //refresh background image

    [self CreateBackgroundTransparency]; //create transparent background if colors changed - only from time to time


    self.contentView.parentController = self;
    [self.contentView FillData]; //Fill UIView with data - set labels texts to new ones

    //_needRefresh is set to YES after application comes from background

    [self.contentView setNeedsDisplay]; //This do nothing ?

    [_grad display]; //refresh gradient

}); 
}

And here is the selector called after loading the data (in MainViewController)

-(void)FinishDownload:(NSNotification *)notification
{
    dispatch_async(dispatch_get_main_queue(), ^{

        [_activeViewController FillData]; //call method shown before

        //try call some more refresh - also useless
        [self.pageControl setNeedsDisplay];

         //[self reloadInputViews];
         [self.view setNeedsDisplay];


    });

} 

In AppDelegate, for me this comes from the background for the application:

-(void)applicationWillEnterForeground:(UIApplication *)application
{
    MainViewController *main = (MainViewController *)[(SWRevealViewController *)self.window.rootViewController frontViewController];


    [main UpdateData];
} 

In MainViewController

-(void)UpdateData
{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FinishForecastDownload:) name:@"FinishDownload" object:nil]; //create selector

    [[DataManager SharedManager] DownloadForecastDataWithAfterSelector:@"FinishDownload"]; //trigger download
}
+4
source share
3 answers

. UIPageControllView . - .

, .

0

:

[self.view performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];

:

http://blackpixel.com/blog/2013/11/performselectoronmainthread-vs-dispatch-async.html

+1

setNeedsDisplay drawRect: " " , .

drawRect: .., , , setNeedsLayout/layoutSubviews.

updateUI, , , (setNeedsDisplay) (drawRect:).


You must install all of yours label.text, imageView.imageetc. in the method updateUI. It is also recommended that you try to set these values ​​only by this method, and not directly from any method.

0
source

Source: https://habr.com/ru/post/1547417/


All Articles