2012-03-12 57 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]; 
} 
相關問題