gpt4 book ai didi

iOS 图形界面刷新

转载 作者:可可西里 更新时间:2023-11-01 06:07:25 26 4
gpt4 key购买 nike

我在我的 GUI 上使用 setNeedsDisplay,但有时没有完成更新。我正在使用 UIPageControllView,每个页面都有 UIScrollView,里面有 UIView

我有以下管道:

1) 应用程序来自后台 - 称为 applicationWillEnterForeground

2) 开始从服务器下载数据

2.1)数据下载完成后,触发selector

3) 使用 dispatch_asyncdispatch_get_main_queue() 用新数据填充标签、图像等

3.1) 在 View 上调用setNeedsDisplay(也尝试在 ScrollView 和页面 Controller 上)

问题是,调用了步骤 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];
}

在主视图 Controller 中

-(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 图形界面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24611975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com