如何将警报消息文本字段输入值分配给按钮?
在下面的代码中,我正在为textfield分配值,但需求是通过警告消息为按钮而不是textfeild分配值,帮助我解决iPhone中的问题。
-(IBAction)alertmessage{
[self setingValue];
}
-(void)setingValue{
myAlert = [[UIAlertView alloc] initWithTitle:@"Enter year" message:@"alert message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[myAlert addTextFieldWithValue:@"" label:@"entervalue"];
alertTextField=[myAlert textFieldAtIndex:0];
alertTextField.keyboardType=UIKeyboardTypeAlphabet;
alertTextField.clearsOnBeginEditing=YES;
alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
[myAlert show];
[myAlert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Ok"]) {
yearSelection.text= alertTextField.text;
}
}
如果我从警报文本字段输入键盘值作为必须分配或显示在按钮上的输入类型。
答案 0 :(得分:2)
-(void)setingValue{
myAlert = [[UIAlertView alloc] initWithTitle:@"Enter year" message:@"alert message"
delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertTextField=[UITextfiled alloc]initwithFrame:CGRectFrame:(5,25,200,35)]; //set the frame as you need.
alertTextField.Placeholder=@"Enter Value";
alertTextField.keyboardType=UIKeyboardTypeAlphabet;
alertTextField.clearsOnBeginEditing=YES;
alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
[myAlert addSubview:alertTextFiedl];
[alertTextField release];
[myAlert show];
[myAlert release];
}