【发布时间】:2012-02-02 07:01:22
【问题描述】:
目前我在使用-(void)viewDidLoad 中的两个函数时遇到问题,这两个函数都使用NSUrlRequest 将HTTPPost 发送到网络服务以接收数据。
直到[self bar] 决定在[self foo] 完全完成之前开始工作,它才能正常工作。那么,在开始 [self foo] 之前,有没有什么聪明的方法可以检查 [self bar] 是否完全完成?
-(void)viewDidLoad{
[self foo]; // initiates a nsxmlparsercall to a webservice to get values.
[self bar]; // relies on the values recieved from [self foo] to make it's own call.
/* However, [self bar] always crashes before initiating it's request.
/* It crashes when the variables that are being sent with the poststring
/* are being set, as they are null.
/* Which means that the `[self foo]` doesnt get completed before starting [self bar];
}
在这一点上我可能很不高兴,我什至考虑过覆盖-(void)viewDidload 并设置一个布尔值来控制何时可以触发第二个函数,但这似乎是非常糟糕的编码..
任何关于如何为我指明正确方向的建议和/或提示将不胜感激。提前致谢。
【问题讨论】:
-
我认为你应该在解析完这样的响应后把功能栏放在上面。 [xmlParser 解析]; [自我栏];
-
如果我在后台线程中解析会有问题吗?