我使用以下代码在UIAlertView中添加文本字段。它在Simulator(iOS SDK 5.0)中工作正常,但是当我在设备(iOS 4.0.1)中安装时,我收到“无法识别的选择器发送到实例错误”
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter your name" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 9001;
[alert show];
[alert release];
答案 0 :(得分:1)
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"My Test Alert" message:@"what do you want" delegate:nil cancelButtonTitle:@"tell me" otherButtonTitles:@"Cancel", nil];
[myAlert addTextFieldWithValue:@"nothing" label:@"say something"];
UITextField * aTextFld = [myAlert textFieldAtIndex: 0];
aTextFld.clearButtonMode = UITextFieldViewModeWhileEditing;
aTextFld.autocorrectionType = UITextAutocorrectionTypeNo;
[myAlert show];
[myAlert release];
答案 1 :(得分:0)
从此处加入图书馆:http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
尝试使用以下代码:
AlertPrompt *prompt = [AlertPrompt alloc];
prompt.tag = 100;
prompt = [prompt initWithTitle:@"Enter a name" message:@" " delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Save"];
[prompt show];
[prompt release];
答案 2 :(得分:0)
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Please enter your name:" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * alertTextField = [alert textFieldAtIndex:0];
alertTextField.keyboardType = UIKeyboardTypeNumberPad;
alertTextField.placeholder = @"Enter your name";
[alert show];
[alert release];