Posts

Showing posts from February, 2010

UIAlert View with UITextField and Controls

Image
Apples philosophy with UIAlert view is to deliver alerts and offer very limited control. There are many hacks on the internet to add a UITextField subview and use its value. The most effective way I found to do this is as follows:
Alright, here's the goods. The first thing that you'll want to do is to alloc your UIAlertView and then initWithTitle:message:delegate:cancelButtonTitle: otherButtonTitles: just like normal. Then with all that good stuff done, you use the method addTextFieldWithValue:label:. The value is for initializing some text into the text field. The label is for setting a placeholder. Here's some example code.

Code: UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Alert title" message:@"alert message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [myAlert addTextFieldWithValue:nil label:@""]; [[myAlert textField] setTextAlignment:UITextAlignmentCenter]; [[myAlert textField]…