how to add a UITableView into UIAlertView in iOS 7

纵饮孤独 提交于 2019-11-29 12:02:02

You can change accessoryView to any own customContentView in a standard alert view in iOS7

[alertView setValue:customContentView forKey:@"accessoryView"];

Note that you must call this before [alertView show].

Simplest illustrating example:

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
v.backgroundColor = [UIColor yellowColor];
[av setValue:v forKey:@"accessoryView"];
[av show];

Real tableView as the subview of UIAlertView example:

You can't. Apple deprecated ability to add any subviews to UIAlertView in iOS 7. Which I think is a good decision. A lot of people abused UIAlertView.

Creating a custom view is a good idea, but that's not what you wrote in your code. It seems like you are adding subviews to UIAlertView again.

See Alert View UI guide here.

you'll have to subclass UIViewController and use its preferredContentSize property to do some 'custom modal' mimicking UIAlertView layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!