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);

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

相关推荐
檀越剑指大厂19 分钟前
【高效开发工具系列】Blackmagic Disk Speed Test for Mac:专业硬盘测速工具
macos
咕噜企业签名分发-淼淼2 小时前
开发源码搭建一码双端应用分发平台教程:逐步分析注意事项
android·ios
阿福不是狗7 小时前
Python使用总结之Mac安装docker并配置wechaty
python·macos·docker
gen_7 小时前
mac环境下的python、pycharm和pip安装使用
python·macos·pycharm
键盘敲没电12 小时前
【IOS】GCD学习
学习·ios·objective-c·xcode
SY.ZHOU12 小时前
Significant Location Change
macos·ios·cocoa
buyue__15 小时前
MacOS解决局域网“没有到达主机的路由 no route to host“
macos
吴Wu涛涛涛涛涛Tao20 小时前
深入理解 Swift Codable:从基础到进阶
ios
明月看潮生1 天前
青少年编程与数学 01-011 系统软件简介 05 macOS操作系统
macos·青少年编程·操作系统·系统软件·编程与数学