直到 iOS7 在自定义 View 中,我们可以按照下图将 tableview 设置为 alert。
但在 iOS8 中 UITableview 不工作。我可以把它放在 tableview 中,但 tableview 没有滚动,也没有检测到对任何单元格的任何点击。
那么,我该如何实现这种类型的 AlertController 呢?
最佳答案
礼貌 StackOverFlow
用户我能够完成这项任务......
这是我的代码...
UIViewController *controller = [[UIViewController alloc]init];
UITableView *alertTableView;
if (array.count < 4) {
CGRect rect = CGRectMake(0, 0, 272, 100);
[controller setPreferredContentSize:rect.size];
alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 272, 100)];
}
else if (array.count < 6){
CGRect rect = CGRectMake(0, 0, 272, 150);
[controller setPreferredContentSize:rect.size];
alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 272, 150)];
}
else if (array.count < 8){
CGRect rect = CGRectMake(0, 0, 272, 200);
[controller setPreferredContentSize:rect.size];
alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 272, 200)];
}
else{
CGRect rect = CGRectMake(0, 0, 272, 250);
[controller setPreferredContentSize:rect.size];
alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 272, 250)];
}
alertTableView.delegate = self;
alertTableView.dataSource = self;
alertTableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
[alertTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[alertTableView setTag:kAlertTableViewTag];
[controller.view addSubview:alertTableView];
[controller.view bringSubviewToFront:alertTableView];
[controller.view setUserInteractionEnabled:YES];
[alertTableView setUserInteractionEnabled:YES];
[alertTableView setAllowsSelection:YES];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
[alertController setValue:controller forKey:@"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
关于objective-c - 如何在 iOS8 的 UIAlertController 中添加 UITableview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27635814/