UIAlertView使用步骤

本文介绍如何在iOS应用中使用UIAlertView并实现其委托模式。通过具体代码示例展示了UIAlertView的初始化过程,包括设置标题、消息内容、按钮标题等,并定义了alertView的代理方法来响应用户的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.增加委托,在头文件中增加以下代码:

UIViewController<UIAlertViewDelegate>

2.定义对象及委托处理方法

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"

                                                        message:@"网络差,请重试!"

                                                       delegate:self

                                              cancelButtonTitle:@"取消"

                                              otherButtonTitles:@"重试",nil];//otherButtonTitles不可修改名称

    [alertView show];

3.添加默认的处理方法

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    UIView *view = (UIView*)[self.view viewWithTag:120];

    switch (buttonIndex) {

        case 0:

            [view removeFromSuperview];

            break;

        case 1:

            [self viewDidLoad];

            break;

        default:

            break;

    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值