无法显示微调框 [英] Can’t get a spinner to appear

查看:62
本文介绍了无法显示微调框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用微调器.但是,下面的这段代码不会显示微调器,我不确定为什么.如何使这项工作?顺便说一句,这是从我创建的提交按钮调用.

I would like to use a spinner. But, this code below does not display a spinner and I'm not sure why. How to make this work? BTW, It is being called from a submit button I created.

//spinner declared in .h file
UIActivityIndicatorView   *aSpinner; 

//throw up spinner from submit btn we created
aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleWhiteLarge];

[self.view addSubview:aSpinner]; 
[aSpinner release]; 
[aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];

//get rid of spinner when finished delegate is fired
- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"REQUEST FINISHED"); 
    [aSpinner stopAnimating]; 
    //[aSpinner release]; 
} 

推荐答案

如果在显示微调框后立即调用一些阻止代码,则UI不会得到更新,因为它仅在运行主运行循环时才更新.如果这确实是问题的根源,则当您注释掉 [request startSynchronous] 行以进行测试时,微调框应该出现.

If you call some blocking code immediately after you display the spinner, the UI won’t get updated, since it only updates when the main run loop is running. If this really is the source of the problem, the spinner should show up when you comment out the [request startSynchronous] line for a test.

解决方案是使用异步请求.委托代码看起来已经完成了,但是另一方面,start调用提到了同步操作.介意解释吗?(还是我忽略了某些东西?)

The solution would be to use an asynchronous request. The delegating code looks like you already do that, but on the other hand the start call mentions synchronous operation. Care to explain? (Or did I overlook something?)

这篇关于无法显示微调框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆