problem while displaying UIAlertview with textfield and buttons
I need to place 3 buttons and one textfield in UIAlertview. I wrote code like this.
UIAlertView *share = [[UIAlertView alloc] initWithTitle:@"Refresh" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", @"Contacts", nil];
share.tag = 2;
[share setDelegate:self];
[share setTitle:@"Enter Name"];
[share setMessage:@" "];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[nameField setKeyboardType:UIKeyboardTypePhonePad];
[share addSubview:nameField];
[share show];
[share 开发者_如何转开发release];
[nameField release];
But it displays like this.
If i place 2 buttons it displays fine.
when ever i add new button it add in next row as show above link.
But I need to display all the three buttons in a single column.
How can I do this?
You have to make room for the UITextField by adding a necessary number of @"\n" to your message string.
Add a couple of them (like: @"Are you want to Refresh Data\n\n") and see what happens.
I have tried this method in the past and It worked but I have some problems when rotating the device while the alert is being shown. The layout becomes a mess.
You can also try subclassing UIAlertView like in here
EDIT:
I have just tried and realized that UIAlertView has a max height this is why this is not working(also the reason why it works with 2 buttons and not with 3 or more).
You cannot arrange buttons of UIAlertView, not at least with public APIs, If you are interested in undocumented APIs look at Erica Sadun's book, there is a lot of stuff there regarding UIAlertView customization. But before that, Why do you need these 2 buttons: "OK" and "Done"? Don't they have the same meaning? (at least from the user point of view)
My point is, if its too much work for 3 buttons, then rethink your title/message and maybe it can be done with only 2.
Hope it helps
精彩评论