uitableview - 如何在 iOS 7 中将 UITableView 添加到 UIAlertView

标签 uitableview ios7 uialertview

做了一些谷歌搜索,发现 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];

enter image description here

真正的 tableView 作为 UIAlertView 示例的 subview :

enter image description here

关于uitableview - 如何在 iOS 7 中将 UITableView 添加到 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216477/

相关文章:

iOS - 未调用警报 View 的 segue

swift - 如何使用 Swift 更改 iOS 警告消息框标题和消息中的字体大小

ios - 呈现另一个 View Controller 将 UITableView 滚动到顶部

swift - 在 ios 7(swift) 上使用dispatch_get_global_queue时会发生EXC_BAD_INSTRUCTION

objective-c - 如何在 iOS 标签栏中使用自定义字体

ios - 这是 NSString 内存泄漏吗?

ios - 在 AFHTTPRequestOperation 失败时显示 UIAlertView

ios - 使 UITableView 像 UIPickerView 一样滚动

ios - swift 如何显示除非在到达底部后进一步向上滚动才能看到的页脚?

swift - 由于 CAShapeLayer (Swift 3),延迟的 UITableView 滚动