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

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

相关推荐
sweet丶5 小时前
iOS 蓝牙开发深入总结
ios·蓝牙
Digitally8 小时前
免费将 iPhone 音乐传输到电脑:6 种方法
ios·iphone
带娃的IT创业者9 小时前
MLX-VLM:在Mac上解锁视觉语言模型的本地推理与微调能力
人工智能·macos·语言模型·mac·视觉语言模型·mlx·本地推理
Nan-h19 小时前
Omi 录屏专家点击缩放是什么?录制、编辑、预览、导出流程说明
macos
一个人旅程~9 小时前
使用OpenCore-Patcher解决Monterey 蓝牙故障处理完整使用方法及卸载回退指导书
经验分享·macos·电脑
黄毛火烧雪下10 小时前
Mac 上用 Charles 抓取 iPhone 的 HTTPS 请求
网络协议·macos·https
_柒安13 小时前
macsvn:Mac 上的 SVN 客户端工具介绍
macos·svn
kevinli13 小时前
帮Apple修Bug
ios·llvm
2501_9159214314 小时前
Xcode与iOS SDK完整教程:从下载安装到配置优化全解析
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
zandy101114 小时前
Hermes Agent 完全安装指南(Linux、macOS、Windows、Android)
linux·windows·macos·agent·安装指南