如何在iPhone中创建警报框? [英] How to create an alert box in iphone?

查看:94
本文介绍了如何在iPhone中创建警报框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个警告类型框,以便当用户尝试删除某些内容时,它会说你确定,然后如果他们确定则为是或否。在iPhone中执行此操作的最佳方法是什么?

解决方案

A UIAlertView 是最好的方法。它将动画显示在屏幕中间,使背景变暗,并强制用户解决它,然后返回到应用程序的正常功能。



您可以创建一个 UIAlertView 是这样的:

  UIAlertView * alert = [[UIAlertView alloc ] initWithTitle:@等待消息:@你确定要删除它。这个动作无法撤消委托:self cancelButtonTitle:@删除otherButtonTitles:@取消,nil]; 
[alert show];

这将显示消息。



然后检查他们是否点击了删除或取消,请使用:

   - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex {
if(buttonIndex == 0){
//删除它
}
}

确保在头文件( .h )中包含 UIAlertViewDelegate < UIAlertViewDelegate> 放在您的类继承的旁边(即。 UIViewController UITableViewController 等。)



有关 UIAlertViews所有细节的更多信息查看 Apple的文档 / p>

希望有帮助


I would like to make an alert type box so that when the user tries to delete something, it says, "are you sure" and then has a yes or no for if they are sure. What would be the best way to do this in iphone?

解决方案

A UIAlertView is the best way to do that. It will animate into the middle of the screen, dim the background, and force the user to address it, before returning to the normal functions of your app.

You can create a UIAlertView like this:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@"Are you sure you want to delete this.  This action cannot be undone" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
[alert show];

That will display the message.

Then to check whether they tapped delete or cancel, use this:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0){
        //delete it
    }
}

Make sure in your header file (.h), you include the UIAlertViewDelegate by putting <UIAlertViewDelegate>, next to whatever your class inherits from (ie. UIViewController or UITableViewController, etc.)

For more infomation on all the specifics of UIAlertViews check out Apple's Docs Here

Hope that helps

这篇关于如何在iPhone中创建警报框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆