无法出现微调器
我想使用旋转器。但是,下面的代码不显示 旋转器,我不知道为什么。如何使这项工作有效?顺便说一句,它正在 从我创建的提交按钮调用。
//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];
}
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也在头文件中添加一个属性:
不要忘记在 .m 文件中综合!
在你的 dealloc 方法中你可以写: [aSpinner release];然而,这只是众多方法中的一种。
Add a property in the header file as-well:
Don't forget to synthesize in .m file!
In your dealloc method you write: [aSpinner release]; This is however just one of many approaches.
问题可能出在您要添加微调器的视图中。是否有能力并且具有显示活动指示器的尺寸? (例如UIBarButtonItems无法处理addSubview)
The problem could be in the view that you're adding the spinner to. Is is capable of, and does it have the dimensions to display the activity indicator ? (e.g. UIBarButtonItems cannot handle addSubview)
如果您在显示微调器后立即调用一些阻塞代码,则 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.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?)