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];
[self CreateBackgroundTransparency];
self.contentView.parentController = self;
[self.contentView FillData];
[self.contentView setNeedsDisplay];
[_grad display];
});
}
And here is the selector called after loading the data (in MainViewController)
-(void)FinishDownload:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
[_activeViewController FillData];
[self.pageControl setNeedsDisplay];
[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];
[[DataManager SharedManager] DownloadForecastDataWithAfterSelector:@"FinishDownload"];
}