UIAlertController

本文详细介绍了UIAlertController和UIAlertAction在iOS开发中的使用方法,包括如何创建弹框控制器、设置样式及添加事件处理等核心功能。

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

UIAlertController 框架内容

//UIAlertController头文件
@interface **UIAlertController** : UIViewController

//类方法创建弹框控制器
//title:标题
//message:信息
//preferredStyle:类型
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

//添加事件
//action:事件
- (void)addAction:(UIAlertAction *)action;
@end

UIAlertController 类初始化方法

+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

UIAlertAction 框架内容

NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>

+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;

@property (nullable, nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) UIAlertActionStyle style;
@property (nonatomic, getter=isEnabled) BOOL enabled;

@end
#pragma mark -设置单元格编辑模式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return _style;
}
根据点击确定按钮拿出输入数据并且加入到数组中
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
#pragma mark -根据点击确定按钮拿出输入数据并且加入到数组中
UIAlertAction* isOK  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

    PersonModel* model = [[PersonModel alloc]init];
    //取出数据  根据alert.textFields数组下标
    model.name = alert.textFields[0].text;
    model.phoneNum = alert.textFields[1].text;
    model.address = alert.textFields[2].text;
    model.sex = alert.textFields[3].text;
    //插入数据
    [self.person_array insertObject:model atIndex:indexPath.row];
    //刷新数据
    [self.tableView reloadData];
}];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值