2013-12-12 51 views
0

我剛開始iOS開發,現在我卡住了。我有一個表格單元格,用戶不能看到數據。在它旁邊,有兩個按鈕。一個要刪除,一個要編輯。編輯部分是我卡住的地方。我有一個標籤字段。當用戶點擊編輯按鈕時,提示應該出現在用戶可以輸入數據的地方。我已經找到了一些可以做到的事情。但是,沒有任何保存按鈕,我不知道我怎麼會那麼變量保存到NSString提示用戶輸入並存儲數據

UIAlertView * alert  = [[UIAlertView alloc] initWithTitle:@"Name der neuen Liste" message:@"" delegate:self cancelButtonTitle:@"Abbrechen" otherButtonTitles:nil]; 
alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
[alert show]; 

我現在有這個。 l現在彈出一個提示,我可以在那裏寫點東西,但不能保存。之後我可以按取消。我如何使用iOS中的用戶輸入?我不想將該標籤作爲UITextField使用,因爲它必須是可點擊才能執行的其他操作。

回答

1

試試這個:

- (void)noteInput 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"input" 
                message:@"input" 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"Save", nil]; 

    [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput]; 
    [alertView show]; 

} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if(buttonIndex == 1) 
    { 
     UITextField *noteText = [alertView textFieldAtIndex:0]; 
     NSString *note = noteText.text; 
    } 
} 
+0

謝謝!這很容易:) – Musterknabe

+0

我必須再等2分鐘。否則我已經;) – Musterknabe

1

嘗試在otherButtonTitles中添加一個Save按鈕。然後,在你UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 1) { 
     // Save button pressed 
    } 
}