iPhone导航栏标题视图同步请求问题
这是我的情况:我正在发出同步 HTTP 请求来收集数据,但在此之前我想在导航栏标题视图中放置一个加载视图。请求结束后我想将 titleView 返回为零。
[self showLoading]; //Create loading view and place in the titleView of the nav bar.
[self makeHTTPconnection]; //Creates the synchronous request
[self endLoading]; //returns the nav bar titleView back to nil.
我知道加载视图有效,因为请求结束后会显示加载视图。
我的问题:此时应该很明显,但基本上我想推迟 [self makeHTTPconnection]
运行,直到 [self showLoading]
完成。
谢谢你的时间。
Here's my situation: I am making synchronous HTTP requests to collect data but before hand I want to place a loading view within the navigation bar title view. After the request is over I want to return the titleView back to nil.
[self showLoading]; //Create loading view and place in the titleView of the nav bar.
[self makeHTTPconnection]; //Creates the synchronous request
[self endLoading]; //returns the nav bar titleView back to nil.
I know the loading view works because after the request is over the loading view is shown.
My Problem: It should be obvious at this point but basically I want to delay the[self makeHTTPconnection]
function until the [self showLoading]
has completed.
Thanks for you time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过同步方法来做到这一点。
当您发送[self showLoading]消息时,在整个方法完成之前UI不会更新,因此它已经完成了其他两个任务(makeHTTPConnection和< em>结束加载)。因此,您永远不会看到加载视图。
这种情况的一个可能的解决方案是并发工作:
然后您必须添加 *_sendRequest* 方法:
You can't do that in a synchronous approach.
When you would send [self showLoading] message, the UI wouldn't be updated until the entire method finishes, so it would already finish the other two tasks (makeHTTPConnection and endLoading). As a result, you would never see the loading view.
A possible solution for this situation would be working concurrently:
Then you must to add the *_sendRequest* method: