问题
My app was recently rejected due to using a private API (addTextField:
method for UIAlertView
, which is quite useful, might I add).
Is there any non-private alternative to UIAlertView
's undocumented addTextFieldWithValue:label:
?
Thanks SO much in advance!
回答1:
create the text field as a subview of the UIAlertView
// Ask for Username and password.
alertView = [[UIAlertView alloc] initWithTitle:_title message:@"\n \n \n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
// Adds a username Field
utextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
utextfield.placeholder = @"Username";
[utextfield setBackgroundColor:[UIColor whiteColor]];
utextfield.enablesReturnKeyAutomatically = YES;
[utextfield setReturnKeyType:UIReturnKeyDone];
[utextfield setDelegate:self];
[alertView addSubview:utextfield];
// Show alert on screen.
[alertView show];
[alertView release];
回答2:
Check out this Open Source code on GitHub for adding UITextFields to a UIAlertView.
http://github.com/enormego/EGOTextFieldAlertView
来源:https://stackoverflow.com/questions/3784134/any-non-private-api-alternative-for-this