iOS-8及更高版本 - UIAlertController中的UITableView [英] iOS-8 and later - UITableView inside an UIAlertController
本文介绍了iOS-8及更高版本 - UIAlertController中的UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用 accessoryView UIAlertView
中添加任何自定义用户界面
code>喜欢 UITableView
但我现在很好奇,如果我们仍然可以在一个内部添加自定义UI
UIAlertController
,我想要的是一个 UITableViewController
里面的 UIAlertController
明确了解。
I know how to add any Custom UI
inside UIAlertView
by using accessoryView
like UITableView
but I am now curious that if we still have option to add Custom UI
inside an UIAlertController
, what I am wanting to have is a UITableViewController
inside an UIAlertController
with clear understanding.
推荐答案
感谢StackOverflow用户我能够完成这项任务。
Courtesy of StackOverflow users I was able to do this task.
这是我的代码:
UIViewController *controller = [[UIViewController alloc]init];
UITableView *alertTableView;
CGRect rect;
if (array.count < 4) {
rect = CGRectMake(0, 0, 272, 100);
[controller setPreferredContentSize:rect.size];
}
else if (array.count < 6){
rect = CGRectMake(0, 0, 272, 150);
[controller setPreferredContentSize:rect.size];
}
else if (array.count < 8){
rect = CGRectMake(0, 0, 272, 200);
[controller setPreferredContentSize:rect.size];
}
else {
rect = CGRectMake(0, 0, 272, 250);
[controller setPreferredContentSize:rect.size];
}
alertTableView = [[UITableView alloc]initWithFrame:rect];
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];
这篇关于iOS-8及更高版本 - UIAlertController中的UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文