做了一些谷歌搜索,发现 iOS 7 不再支持 subview 。
一些人建议创建自定义 View ,但我不知道我该怎么做。
这是我的代码,有人能指出我正确的方向吗?
-(IBAction)click_select_fruit_type
{
select_dialog = [[[UIAlertView alloc] init] retain];
[select_dialog setDelegate:self];
[select_dialog setTitle:@"Fruit Type"];
[select_dialog setMessage:@"\n\n\n\n"];
[select_dialog addButtonWithTitle:@"Cancel"];
idType_table = [[UITableView alloc]initWithFrame:CGRectMake(20, 45, 245, 90)];
idType_table.delegate = self;
idType_table.dataSource = self;
[select_dialog addSubview:idType_table];
[idType_table reloadData];
[select_dialog show];
[select_dialog release];
}
最佳答案
您可以在 iOS7 的标准警报 View 中将附件 View 更改为任何自己的自定义内容 View
[alertView setValue:customContentView forKey:@"accessoryView"];
请注意,您必须在 [alertView show] 之前调用它。
最简单的说明示例:
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];
真正的 tableView 作为 UIAlertView 示例的 subview :
关于uitableview - 如何在 iOS 7 中将 UITableView 添加到 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216477/