开发者

How to add UITableView to UIAlertView?

开发者 https://www.devze.com 2023-01-10 04:38 出处:网络
I create a class: @interface myUITableViewController : UIViewControll开发者_如何学Goer { NSArray *listData;

I create a class:

@interface myUITableViewController : UIViewControll开发者_如何学Goer { NSArray *listData; } ...

and later,I do so:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil    delegate:self cancelButtonTitle:nil otherButtonTitles:nil];

myUITableViewController *myUITable = [[myUITableViewController alloc] init];

[alert addSubview:myUITable.view];

[alert show];

After running,the result is that the myUITable.view's size is bigger than alert. Why? Please tell me if you know. Thank you!


UIAlert is not really meant to be used like that. You should make your own custom UIView and add whatever content you need in it (the table and buttons). Then handle how it shows and hide yourself.

Even if you manage to get it shown correctly chances are it might break in the future. In one of my apps i was showing an alert with a UITextField. I was making space for it by adding "\n" to the message. In later iOS versions this stopped working and it looked really awful...

0

精彩评论

暂无评论...
验证码 换一张
取 消