0

我试图在应用程序启动后在模式视图中显示我的远程配置设置。一切都已正确连接,但视图会在configs对象从其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
4

1 回答 1

1

您应该使 MYSettingsViewController 成为 MYRemoteConfig 控制器的委托,在 MYRemoteConfig 中创建委托协议,并在 connectionDidFinishLoading 方法中调用您在该协议中创建的方法。然后在 MYSettingsViewController 中实现该方法将更新客户和课程标签。

于 2013-06-04T22:05:53.100 回答