我试图在应用程序启动后在模式视图中显示我的远程配置设置。一切正常,但视图更新其configs
对象从它的NSURLConnection
委托方法更新之前。如何在继续之前等待NSURLConnection委托完成?
我正在寻找一种解决方案,在尝试更新视图之前让委托方法完成。我宁愿不把这些功能放在委托方法本身中,所以我可以在其他情况下使用MYRemoteConfig
。
我怀疑这个解决方案是显而易见的,但是我已经很长时间没有考虑这个问题了。
在viewDidAppear{}
在MYSettingsViewController.m
MYRemoteConfig* config = [[MYRemoteConfig alloc] init];
[configs updateSettings]; // I need these delegate methods to be done
// before the next line
self.customerLabel.text = configs.customer; // Updates with empty box
self.courseLabel.text = configs.course;
-
updateSettings{}
在MYRemoteConfig.m
// code that gets uuid and sets up post request //
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request
delegate:self];
[connection start];
NSLog(@"Connection should have started.");
然后在connectionDidFinishLoading{}
:(数据附加到局部变量之后)
// pull JSON objects into dictionary
[self updateProfile:settingsDictionary;
NSLog(@"%@", settingsDictionary); //works
updateProfile{}
:
// code that sets config attributes in singleton object //
self.customer = [settings objectForKey:@"Customer"]; // I need this data
self.course = [settings objectForKey:@"Course"]; // in my view controller
这已被回答http://stackoverflow.com/questions/16880686/different-nsstring-results-from-url-download –
安装通知可能吗? ;-) NSNotificationCenter –
或委托给你的'MYRemoteConfig'类。 – danypata