我有以下管道:
1)应用程序来自后台 – 名为applicationWillEnterForeground
2)从服务器开始下载数据
2.1)数据下载完成后,触发选择器
3)使用dispatch_async和dispatch_get_main_queue()来填充新数据的标签,图像等
3.1)在视图上调用setNeedsdisplay(也尝试滚动视图和页面控制器)
问题是,调用了步骤3.1,但只是不时地改变apper.如果我交换页面,刷新完成,我可以看到新数据(所以下载工作正常).但是没有手动翻页,就没有更新.
有帮助吗?
编辑:步骤3和3.1中的代码(删除了注释中指向的_needRefresh变量)
-(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}); }
这里是数据下载后调用的选择器(在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]; });}
在AppDelegate中我有这个应用程序来自后台:
-(voID)applicationWillEnterForeground:(UIApplication *)application{ MainVIEwController *main = (MainVIEwController *)[(SWRevealVIEwController *)self.window.rootVIEwController frontVIEwController]; [main UpdateData];}
在MainVIEwController中
-(voID)UpdateData{ [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(FinishForecastDownload:) name:@"FinishDownload" object:nil]; //create selector [[DataManager SharedManager] DownloadForecastDataWithAfterSelector:@"FinishDownload"]; //trigger download}解决方法 试试这个:
[self.vIEw performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
或检查此链接:
http://blackpixel.com/blog/2013/11/performselectoronmainthread-vs-dispatch-async.html
总结以上是内存溢出为你收集整理的iOS GUI刷新全部内容,希望文章能够帮你解决iOS GUI刷新所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)