UIAlertView未显示何时更改其他视图

时间:2011-12-29 05:27:22

标签: iphone uinavigationcontroller uialertview

我想要发生的事情,按顺序:警告框弹出说处理(没有按钮),主要处理功能被调用,当完成警报框消失,然后我的导航控制器移动到下一个视图中系列。

实际发生的情况:当应用处理时窗口冻结,然后当导航控制器切换到下一个视图时,警告框会立即显示并消失。

关于如何解决此问题的最佳建议?

代码:     [_navigationController dismissModalViewControllerAnimated:NO]; //相机解散     UIAlertView *警报;

alert = [[[UIAlertView alloc] initWithTitle:@"Analyzing\nPlease Wait..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

[self processImage];

[alert dismissWithClickedButtonIndex:0 animated:YES];
[self gotoResults];

2 个答案:

答案 0 :(得分:2)

alert = [[[UIAlertView alloc] initWithTitle:@"Analyzing\nPlease Wait..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

调用[alert show]时,UI事件被推送到主运行循环中。您可以在另一个函数中处理其他任务。例如,名为foo的函数处理其他任务。在致电[alert show]后,我们致电[self performSelector:@selector(foo) withObject:nil afterDelay:0.1]来调用foo。这将给运行循环一些时间来处理警报视图的显示事件。

- (void)foo {
  UIAlert *alert = ... ///< come from above 
  [self processImage];

  [alert dismissWithClickedButtonIndex:0 animated:YES];
  [self gotoResults];
}

编辑:    您可以在this apple official document中阅读-performSelector:withObject:afterDelay :.您可以为afterDelay指定0.0作为参数,文档说:

  

delay


发送邮件的最短时间。指定一个   延迟0不一定会导致选择器被执行   立即。选择器仍在线程的运行循环中排队   尽快进行。

答案 1 :(得分:1)

[self processImage]在主线程中运行导致窗口冻结问题... 所以你可以使用

[NSThread detachNewThread: .....]

用于调用AlertView方法