除非我注释掉自动关闭,否则看不到我的alertView
我正在实现一个简单的警报视图,其中包含活动指示器,以便在应用程序执行数据库恢复时向用户显示。一切都很好,除了我看不到警报视图,除非我注释掉自动关闭行(这里的最后一个)。
好吧,数据库的恢复非常快,但我仍然希望看到它,即使只是一瞬间,不是吗?我可以看到动画期间屏幕变得有点暗,但仅此而已。我还尝试放置一个 for 循环来延长时间,时间延长但仍然没有警报视图。
警报视图的调用方式没有任何问题,因为如果我评论解雇,我就可以看到它......只能永远看到。这里有人有想法吗?
在有人说之前,我尝试将alertView的委托更改为self
,如发布的此处,但没有帮助。
// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];
// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];
// Finally we operate the restore
[[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];
// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];
I am implementing a simple alert view with activity indicator to show to the user while the app is performing the restore of the database. Everything is fine except that I can't see the alert view, unless I comment out the automatic dismiss line (last one here).
Ok, the restore of the database is quite quick, but still I would expect to see it even if for an instant, no? I can see the screen get's a little darker during animation but that's all. I also tried putting a for loop to extend the time, the time extends but still no alert view.
There is nothing wrong in the way the alert view is called, since if I comment the dismiss, I can see it...only forever. Anyone has an idea here?
Before anyone says it, I tried changing the delegate of the alertView to self
as posted here, but it didn't help.
// First we prepare the activity indicator view to show progress indicator
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityView setFrame:CGRectMake(121.0f, 50.0f, 37.0f, 37.0f)];
[activityView startAnimating];
// Then we put it in an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alertView addSubview:activityView];
[alertView show];
// Finally we operate the restore
[[SQLManager sharedSQL] restoreDatabase:[restoreDatabaseURL path]];
// And we can dismiss the alert view with the progress indicator
[alertView dismissWithClickedButtonIndex:0 animated:NO];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定为什么会发生这种情况,但我偶尔也会遇到这种情况。我得到这样的东西的一种方法是在下一次调用时使用
performSelector:withObject:afterDelay:
,如下所示:performSelector
文档Im not sure why this happens, but I encounter it occasionally as well. One way I have gotten something like this to work is by using
performSelector:withObject:afterDelay:
on the next call, like this:performSelector
Documentation听起来它几乎立刻就自我否定了。如果您添加 for 循环,它可能会冻结所有其他计算,这意味着您的活动视图在循环中断之前不会显示。
您可以尝试使用 NSTimer 调用另一个函数来确定恢复是否完成;
Sounds like it's dismissing itself almost instantaneously. If you add a for loop, it will likely freeze all other computations which means your activity view won't show up until the loop breaks.
You could try using a NSTimer to call another function to determine if the restore is complete or not;