如何在iOS中实现弹出对话框 [英] how to implement a pop up dialog box in iOS
问题描述
计算完毕后,我想显示一个向用户传达信息的弹出框或警告框。有谁知道我在哪里可以找到更多相关信息?
After a calculation, I want to display a pop up or alert box conveying a message to the user. Does anyone know where I can find more information about this?
推荐答案
Yup, UIAlertView
可能就是你要找的东西。这是一个例子:
Yup, a UIAlertView
is probably what you're looking for. Here's an example:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
如果你想做一些更奇特的事情,比如在 UIAlertView
,您可以继承 UIAlertView
并在 init
方法中放入自定义UI组件。如果您想在显示 UIAlertView
后按下按钮,可以在上面设置委托
并实施 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method。
If you want to do something more fancy, say display a custom UI in your UIAlertView
, you can subclass UIAlertView
and put in custom UI components in the init
method. If you want to respond to a button press after a UIAlertView
appears, you can set the delegate
above and implement the - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method.
您可能还想要查看 UIActionSheet
。
这篇关于如何在iOS中实现弹出对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!