网络通话后iPhone视图未刷新
我已经设置了我的应用程序,这样应用程序进入前台时,它会执行一个web调用,从web服务器调用信息,在那里接收和解析JSON,然后离线存储 我的应用程序是一个选项卡式应用程序,每个屏幕上的信息都是从JSON设置的,图像也是从服务器上提取的。因此,我希望每个页面上的信息在完成后更新,但不更新 我现在正在模拟器上运行我的应用程序,以防有什么不同。目前,我获得更新信息的唯一方法是使用ViewDidDisplay,或者从xCode停止并再次启动应用程序 我尝试从AppDelegories调用viewDidLoad类网络通话后iPhone视图未刷新,iphone,xcode,Iphone,Xcode,我已经设置了我的应用程序,这样应用程序进入前台时,它会执行一个web调用,从web服务器调用信息,在那里接收和解析JSON,然后离线存储 我的应用程序是一个选项卡式应用程序,每个屏幕上的信息都是从JSON设置的,图像也是从服务器上提取的。因此,我希望每个页面上的信息在完成后更新,但不更新 我现在正在模拟器上运行我的应用程序,以防有什么不同。目前,我获得更新信息的唯一方法是使用ViewDidDisplay,或者从xCode停止并再次启动应用程序 我尝试从AppDelegories调用viewDid
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
WebCalls *wc = [[WebCalls alloc] init];
DashboardVC *db = [[DashboardVC alloc] init];
[wc setWebCallDidFinish:^(NSString * json, NSString *ID) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
[json writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
NSString *docDir2 = [paths objectAtIndex: 0];
NSString *docFile2 = [docDir2 stringByAppendingPathComponent: @"theID.txt"];
[ID writeToFile:docFile2 atomically:NO encoding:NSUTF8StringEncoding error:Nil];
[db testme];
}];
[wc getData];
}
这将再次调用viewDidLoad,但信息不会更新。你知道为什么吗
Edit:在该类中,它像这样读取JSON
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
[json writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
我可以打印JSON,JSON肯定在更新,但屏幕上的信息不是
编辑:使用web调用更新您可以尝试使用委托方法将获取的数据更新到UI中。JSON解析结束后调用委托方法。我在xml解析方面也做了同样的事情,而且很有效
- (void)parserDidEndDocument:(NSXMLParser*)解析器{ [self.delegate OptimizandDrawShortPath:CoordinateArray] [路线释放]; routeArray=零; }
我很确定,这就是您要查找的内容。修复了此问题。在应用程序中设置定期web调用,当进行web调用时,调用类中的刷新方法。为什么省略web调用代码?这似乎很重要。它是异步的吗?是的,web调用是异步的。wc只是我的WebCall类的一个对象。但是要刷新的代码在方法内部,该方法仅在web调用完成后调用,以显示web调用代码