添加一个简单的UIAlertView [英] Adding a simple UIAlertView
本文介绍了添加一个简单的UIAlertView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用什么样的入门代码制作一个简单的UIAlertView,上面有一个OK按钮?
What is some starter code I could use to make a simple UIAlertView with one "OK" button on it?
推荐答案
当您想要显示警报时,请执行以下操作:
When you want the alert to show, do this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ROFL"
message:@"Dee dee doo doo."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// If you're not using ARC, you will need to release the alert view.
// [alert release];
如果您想在单击按钮时执行某些操作,请实现此委托方法:
If you want to do something when the button is clicked, implement this delegate method:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
// the user clicked OK
if (buttonIndex == 0) {
// do something here...
}
}
并确保您的代表符合 UIAlertViewDelegate
协议:
And make sure your delegate conforms to UIAlertViewDelegate
protocol:
@interface YourViewController : UIViewController <UIAlertViewDelegate>
这篇关于添加一个简单的UIAlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文