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

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

相关推荐
用户223586218201 小时前
WebKit WebPage API 的引入尝试与自研实现
ios
啦啦啦!2 小时前
ChatGPT和Gemini的接入和封装
人工智能·ios·chatgpt
aosky2 小时前
手机远程畅玩OpenAI Codex
macos·智能手机·cocoa
报错小能手3 小时前
ios开发方向——swift并发进阶核心 async/await 详解
开发语言·ios·swift
开心就好20254 小时前
HTTPS超文本传输安全协议全面解析与工作原理
后端·ios
Digitally4 小时前
荣耀手机数据迁移至 iPhone 教程
智能手机·cocoa·iphone
牛马1114 小时前
Flutter iOS 权限配置完整指南(定位权限)
flutter·ios
A_QXBlms4 小时前
多账号轮询架构 — 利用企销宝iPad协议突破单账号群发次数限制
ios·架构·ipad
HH思️️无邪5 小时前
Flutter + iOS 实战指南:教程视频 PiP + 退桌面(可复用模板)
flutter·ios
A懿轩A5 小时前
【2026 最新】Python 下载与安装:在 macOS 下使用 Homebrew 和 pyenv 完美管理多版本 Python
python·macos·mac