我想動態更改rootViewController。這取決於json響應。我有一個BOOL值,它獲得JSON響應後發生變化。問題是即使條件爲真,這個值也不會改變。iOS更改rootViewController動態
我的代碼如下,我把它放在應用程序didFinishLaunchingWithOptions:
isTime = NO;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:
[url
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ]];
__block NSDictionary * json;
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError){
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&connectionError];
NSLog(@"JSON >>>> %@",[json objectForKey:@"status"]);
if ([[json objectForKey:@"status"] isEqualToString:@"ok"]) {
isTime = YES;
}
}];
if(isTime){
//rootView1
}else{
//rootView2
}
我該如何解決呢?有任何想法嗎?
在'-application:didFinishLaunchingWithOptions:'你不能做這樣的事情,__你的整個概念是完全錯誤的。您需要儘快完成午餐,並開始自定義作業網絡操作_after_。 – holex