在iPad上显示弹出对话框

时间:2011-04-19 05:22:23

标签: ios ipad dialog modal-dialog

我想显示一个弹出对话框,通知用户从iPad应用程序访问服务器数据,特别是在拆分视图控制器之上。使用单独的控制器以模态方式执行此操作是最好的方法吗?视图控制器指南指示模态视图控制器是全屏转换,因此在iPad应用程序中不经常使用,所以我想知道是否有更好的方法,因为我只想创建一个带有活动指示器的半透明背景消息。

我不想只使用拆分视图的两个控制器之一,因为它似乎不是正确的方法。

1 个答案:

答案 0 :(得分:0)

你可以用UIAlertView做到这一点。

UIAlertView *alert;

...

alert = [[[UIAlertView alloc] initWithTitle:@"Accessing Data..." 
            message:nil delegate:self cancelButtonTitle:"Cancel" otherButtonTitles: nil] autorelease];

[alert show];

HERE他们讨论如何设置它没有按钮,因此您可以控制何时解除它(如果您试图阻止用户在访问该服务器数据时进行交互)。基本上你最终得到:

UIAlertView *alert;

...

alert = [[[UIAlertView alloc] initWithTitle:@"Accessing Data..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

这是一个内部带有活动指示器的警报视图,你可以解雇:

[alert dismissWithClickedButtonIndex:0 animated:YES];

希望有所帮助。