ios 对话框UIAlertController放 tableview

objectivec 复制代码
//强弱引用
#define kWeakSelf(type)__weak typeof(type)weak##type = type;
-(void) showUIAlertTable
{
    kWeakSelf(self)
    UIAlertController *alert = [UIAlertController      alertControllerWithTitle:NSLocalizedString(@"select_stu", nil)   message:nil   preferredStyle:UIAlertControllerStyleAlert];
    CGRect     frame = self.view.bounds;
    frame = CGRectInset(frame, 0, 0);
    UITableView *tableView2 = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    tableView2.dataSource = self;
    tableView2.delegate = self;
    [tableView2 registerClass:[DevicelistCell class] forCellReuseIdentifier:@"deviceCell"];
    [alert.view addSubview:tableView2];
    [self presentViewController:alert animated:NO completion:nil];
    
}


问题来了,对话框 既然 不在屏幕中间。

解决办法

objectivec 复制代码
-(void) showUIAlertTable
{
    kWeakSelf(self)
    UIAlertController *alert = [UIAlertController      alertControllerWithTitle:NSLocalizedString(@"select_stu", nil)   message:nil   preferredStyle:UIAlertControllerStyleAlert];
    CGRect     frame = self.view.bounds;
    frame = CGRectInset(frame, -50, -300);
    UITableView *tableView2 = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    tableView2.dataSource = self;
    tableView2.delegate = self;
    [tableView2 registerClass:[DevicelistCell class] forCellReuseIdentifier:@"deviceCell"];
    [alert.view addSubview:tableView2];
    [self presentViewController:alert animated:NO completion:nil];
    
}

frame = CGRectInset(frame, -50, -300);

根据各个手机去适配吧。调整到合适的位置。

相关推荐
90后的晨仔7 小时前
Xcode 27.1 下,老工程如何在 iPhone Duo 模拟器上跑起来
ios
90后的晨仔7 小时前
Xcode 27 升级后满屏 deployment target 报错?一文搞定
ios
Karl_fang10 小时前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
二流小码农11 小时前
鸿蒙开发:router组件升级,彻底告别手动配置
android·ios·harmonyos
茶底世界之下18 小时前
雾中山路的冷光层次:用 Awaking 留住红色背影
ios·app·产品
Digitally19 小时前
iPhone 如何添加日历?
ios·iphone
Gracker1 天前
100 Years Life:把体检、睡眠和运动放进同一份健康档案
ios
csdn_aspnet2 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac
秋雨梧桐叶落莳2 天前
【iOS】Block底层详解
macos·ios·cocoa
茶底世界之下2 天前
舞台灯下的萨克斯:用 Awaking 让铜管从蓝幕前亮起来
ios·app·产品