在其按钮下的操作完成之前关闭 actionSheet
我的问题是我有一个 ActionSheet,只有当此按钮下的操作完成时,它才会从屏幕上消失。我的问题是我想在操作表中单击“保存”,然后关闭操作表,然后显示一些警报,通知用户等待保存完成。目前它的工作方式有所不同:首先显示操作表,然后在操作表下保存消息,最后操作表从视图中删除..因此用户看不到任何警报消息。
如何在 xcode 之前关闭 actionSheet 呢?
sheetActionButton下的方法:
- (IBAction)saveAction:(id)sender
{
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[self saveImageToCameraRoll];
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
My problem is that i have an ActionSheet, which is disappearing from screen only when action under this button is completed. My problem is that i want to click 'save' inside my action sheet, then dismiss action sheet and then to show some alert, informing user to wait until saving is done. Currently it works different: firstly action sheet is shown, then there is saving message UNDER action sheet, finally action sheet is removed from view.. so user doesnt see any alert message.
How to dismiss actionSheet earlier than xcode does it?
Method under sheetActionButton:
- (IBAction)saveAction:(id)sender
{
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[self saveImageToCameraRoll];
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将
saveImageToCameraRoll
方法移动到单独的线程上,或者至少在主线程上异步移动。然后您可以消除警报,并且saveAction:
可以在完成之前返回。最简单的方法是使用dispatch_async。使用
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
获取单独线程的队列,或使用dispatch_get_main_queue()
获取主线程。确保不要在其他线程上执行任何 UI 工作(或使用任何非线程安全的 API)!编辑:更多细节:
You should move your
saveImageToCameraRoll
method onto a separate thread, or at least asynchronously on the main thread. Then you can dismiss the alert andsaveAction:
can return before it completes.The simplest way to do this would be using
dispatch_async
. Usedispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
to get a queue for a separate thread, ordispatch_get_main_queue()
for the main thread. Make sure not to do any UI work (or use any APIs which aren't thread-safe) on other threads!Edit: more detail: