我使用NSNotification中心来检测货币的更改,以便我可以更新所有其他类。当货币发生变化时,所有其他类和视图都会更新,但是当货币没有变化时,并且如果您按下返回按钮返回到主页,视图会加载到现有视图的顶部。Objective-C - 在另一个控制器上加载UIViewController
代码NSNotification中心
if ([overviewModel.currency isEqual:@"GBP"]){
[[NSNotificationCenter defaultCenter] postNotificationName:@"DataUpdated"
object:self];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:@"DataUpdated"
object:self];
}
代码在网页处理更新的数据:
for (UIView *b in self.view.subviews) {
[b removeFromSuperview];
}
self.build = [[ApiRequestBuild alloc]initWithVersionKey:kAPI_VERSION_KEY requestType:kAPI_REQUEST_TYPE data:@""];
[self.build setQueryWithSection:@"homepage" value:@"" parameter:@[]];
self.request = [[ApiRequest alloc]init];
self.request.delegate = self;
[self.request sendRequestWithParams:[self.build buildConfig] toUrl:kAPI_URL_STRING];
我知道为什么发生这种情况,该请求被再次发出这样的页面加载在已经存在的页面之上,我不明白的是为什么不从子视图代码中移除视图以及如何才能解决这个问题?谢谢
你试过吗? - https://stackoverflow.com/a/11889296/3548469 –
@Dev_Tandel是的,仍然是同样的问题。我将创建一个全局变量并将其设置为零,然后只有当货币更改时才为其添加值,以便唯一一次更新主页。 –
但为什么要删除子视图?您只需要在货币更改时更新全部 –