2012-07-12 84 views
0

在Xcode 4.3 3中,我創建了一個按鈕,它生成一個彈出式輸入框(按鈕取消&回車),工作正常,如何檢索輸入的數據並將其顯示在標籤中或表?從UIAlertView檢索輸入文本

下面是我的按鈕背後的代碼的樣子。

- (IBAction)car:(UIButton *) sender 

    NSString * title1 = [sender titleForState:UIControlStateNormal]; 

    _mylabel.text = title1; 

     UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Expense Amount in $:" 
         message:@"\n\n" 
         delegate:self 
         cancelButtonTitle:@"Cancel" 
         otherButtonTitles:@"Enter", nil]; 


    _textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)]; 

    [_textField setBackgroundColor:[UIColor whiteColor]]; 

    [_textField setPlaceholder:@"Amount"]; 

    [prompt addSubview:_textField]; 

    _textField.keyboardType = UIKeyboardTypeNumberPad; 


    // show the dialog box 
    [prompt show]; 

    // set cursor and show keyboard 
    [_textField becomeFirstResponder]; 


} 

謝謝你的幫助。

回答

1

正如iOS 5中介紹的那樣,您應該使用UIAlertViewStylePlainTextInput樣式。您將在委託方法中獲得您的價值。不要再使用自定義文本框。

+0

嗨jaydee3,thx爲你的迴應,我是新來的這一切,可以幫助我如何執行這個去? Thx再次。 – Diffrey 2012-07-15 05:04:23

+0

查看本教程的實現:http://mobile.tutsplus.com/tutorials/iphone/ios-5-sdk-uialertview-text-input-and-validation/ – calimarkus 2012-07-15 11:07:48

0

你在這裏試圖解決的是一個常規的UITextField輸入數據保存,無論警報視圖如何。您可以實現在不同的方式和使用的的UITextField委託方法:

textFieldDidChange 
textFieldDoneEditing 
textFieldShouldReturn 

只是實現這些方法之一保存輸入數據,取決於所期望的用戶體驗。

+0

嘿湯米,是的,我試圖保存輸入來自彈出式輸入框的數據,而不是來自常規的UITextField。謝謝 – Diffrey 2012-07-15 05:02:41