UIActivityIndicatorView 无响应
当触发 UIButton
时,将启动 UIActivityIndicator
,然后在 implementLogin
完成时停止:
-(IBAction)loginButton {
NSLog(@"loginButton triggered");
// Checks the Fields are not empty
if ([sessionIdField.text length] != 0 && [usernameField.text length] != 0 ) {
NSLog(@"Beginning Spinner");
// Displays spinner
[activitySpinner startAnimating];
[self implementLogin];
// Displays spinner
[activitySpinner stopAnimating];
}
}
但是在运行时,微调器不会出现!我已将微调器设置为“停止时隐藏”。
当我将活动指示器设置为在视图加载之前进行动画处理时,它会按应有的方式显示,因此我猜测它的 UIButton
有问题...(另外,我正在使用“Touch按钮的“内部”。)
这是一个简单的问题......任何人都可以帮忙吗?
谢谢
When a UIButton
is triggered, a UIActivityIndicator
is started, and then stopped when implementLogin
finishes:
-(IBAction)loginButton {
NSLog(@"loginButton triggered");
// Checks the Fields are not empty
if ([sessionIdField.text length] != 0 && [usernameField.text length] != 0 ) {
NSLog(@"Beginning Spinner");
// Displays spinner
[activitySpinner startAnimating];
[self implementLogin];
// Displays spinner
[activitySpinner stopAnimating];
}
}
However at runtime, the spinner doesn't appear! I have set the spinner to 'hide when stopped'.
When I set the activity indicator to animate before the view loads, it appears as it should, so I'm guessing it has a problem with the UIButton
... (Also, I'm using 'Touch Up Inside' for the button.)
It's a simple problem... Can anyone help?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论
implementLogin
正在做什么(也许是发出网络请求?),它都是在主线程上执行的,这可能会阻止 UI 更新,例如旋转动画。您可以重新编码如下内容:
[代码未经测试,但您明白了。]
这里发生的情况是您将登录任务分派到后台,并且该块要做的最后一件事是停止主屏幕上的微调器线程(作为单独的任务)。
Whatever
implementLogin
is doing (making a network request, perhaps?), it's doing it on the main thread, which is likely blocking UI updates like spinner animation.You could recode something like this:
[Code is untested, but you get the idea.]
What is happening here is that you are dispatching the login task to the background, and the last thing that block will do is stop the spinner on the main thread (as a separate task).
如果没有更多代码,人们只能猜测它不起作用的原因。
我假设“Beginning Spinner”输出正确(?)
如果是这样,您可能没有正确初始化
UIActivityIndicatorView
。看起来像这样吗?
Without more code, one can only guess the reason why it doesn't work.
I assume 'Beginning Spinner' output correctly(?)
If so, you probably didn't properly initialize the
UIActivityIndicatorView
.Does it look like this?