2012-03-12 60 views
0

如何将警报消息文本字段输入值分配给按钮?如何将警报消息文本字段输入值分配给按钮?

在下面的代码中,我将值分配给文本字段,但需求是通过警报消息将值赋给按钮而不是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

**请确保您在发布代码后格式化您的代码** – 2012-03-12 04:43:01

+1

您希望将哪个值分配给按钮..?你的问题并不完全清楚.. – 2012-03-12 05:52:50

回答

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. 
    [email protected]"Enter Value"; 
    alertTextField.keyboardType=UIKeyboardTypeAlphabet; 
    alertTextField.clearsOnBeginEditing=YES; 
    alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing; 
    alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert; 
    [myAlert addSubview:alertTextFiedl]; 
    [alertTextField release]; 
    [myAlert show]; 
    [myAlert release]; 
} 
相关问题