【问题标题】:iPhone navigationBar titleView sync request problemiPhone导航栏titleView同步请求问题
【发布时间】:2011-05-05 23:07:36
【问题描述】:

这是我的情况:我正在发出同步 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] 完成。

感谢您的宝贵时间。

【问题讨论】:

    标签: iphone uiview synchronous navigationbar titleview


    【解决方案1】:

    您无法以同步方式做到这一点。 当您发送 [self showLoading] 消息时,UI 将在整个方法完成之前不会更新,因此它已经完成了其他两个任务(makeHTTPConnection 和 endLoading)。结果,您将永远看不到加载视图。

    这种情况的可能解决方案是同时工作:

    [self showLoading];
    NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_sendRequest) object:nil];
    [queue addOperation:operation];
    [operation release];
    

    那么你必须添加 *_sendRequest* 方法:

    - (void)_sendRequest
    {
        [self makeHTTPConnection];
        //[self endLoading];
        [self performSelectorOnMainThread:@selector(endLoading) withObject:nil waitUntilDone:YES];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 2011-01-09
      • 2018-04-05
      • 1970-01-01
      相关资源
      最近更新 更多