2013-10-07 44 views
3

做了一些谷歌上搜索周围看到的iOS 7如何添加一个UITableView到UIAlertView中在iOS的7

该子视图不再支持一些PPL建议创建自定义视图,但我不知道我怎么能做到这一点。

这是我的代码,任何人都可以指向正确的方向吗?

-(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]; 

} 

回答

1

你不能。苹果已弃用在iOS 7中向UIAlertView添加子视图的能力。我认为这是一个很好的决定。很多人滥用UIAlertView

创建自定义视图是一个好主意,但这不是您在代码中编写的内容。好像你正在为UIAlertView再次添加子视图。

请参阅Alert View UI guide here

+0

从链接,谢谢,我看到有这个东西叫UIActionSheet https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/UIKitUICatalog/UIActionSheet.html#//apple_ref/doc/uid/TP40012857-UIActionSheet-SW1 看起来很有趣 – f00pman

+0

是啊,这是人们也在使用一种解决方案。但是如果你继承UIViewController来模仿UIAlertView,那么它也不是一个非常糟糕的主意。看看Github,看看有没有人做到了。 –

+0

https://github.com/wimagguc/ios-custom-alertview – LoungeKatt

0

你必须继承UIViewController并使用其preferredContentSize属性做一些“定制模式”模仿UIAlertView中布局

13

您可以在一个标准的警报视图中iOS7

改变 accessoryView的任何自己 customContentView
[alertView setValue:customContentView forKey:@"accessoryView"]; 

请注意,您必须在[alertView秀]调用它。

最简单的说明例子:

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

房地产的tableViewUIAlertView中举例子视图:

enter image description here

+0

非常好的解决方案。看起来很诡异,但比试图找到能够添加子视图的UIAlertview备选方案更好。 –

相关问题