Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

ios7 - how to add a UITableView into UIAlertView in 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:@"



"];
[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];

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

enter image description here

Real tableView as the subview of UIAlertView example:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...