如何在iOS 7中的UIAlertView中添加UITableView [英] how to add a UITableView into UIAlertView in iOS 7

查看:115
本文介绍了如何在iOS 7中的UIAlertView中添加UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做了一些谷歌搜索看到iOS 7中不再支持子视图。

did some googling around saw that subview is no longer supported in iOS 7.

有些人建议创建自定义视图,但我不知道我该怎么做。

Some ppl recommend creating custom view, but i am not sure how can i do that.

这是我的代码,有人能指出我正确的方向吗?

Here is my code, can anyone point me in the correct direction?

-(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的标准警报视图中将 accessoryView 更改为任何自己的 customContentView

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

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

请注意,您必须在 [alertView show] 之前调用此方法。

Note that you must call this before [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];

Real tableView 作为 UIAlertView 示例的子视图:

Real tableView as the subview of UIAlertView example:

这篇关于如何在iOS 7中的UIAlertView中添加UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆