2011-04-17 99 views
0

現在我有一個textField。如何處理鍵盤按鈕名稱是「完成」在ios

我輸入一些單詞後,鍵盤會出現。

當我按下鍵盤「完成」時,鍵盤將消失。 (我已經完成了這個功能)

但明年,

我想用核心數據架構當用戶按下按鈕「完成」來插入數據

那麼,如何解決這個問題呢?

我知道如何使用核心數據插入數據,所以你不需要告訴我如何插入數據。

我使用此代碼消失鍵盤。

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField { 
    [txtName resignFirstResponder]; 
    return YES; 
} 

謝謝大家

回答

2

在該示例代碼,我有3個的UITextField。您可以在我們到達最後一個字段後處理您的更新

// I the tag property to indicate which field I am on during runtime 
enum { 
    Line1Tag = 50, 
    Line2Tag, 
    Line3Tag 
}; 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    // The user has pressed the "Return Key" 
    // Which I have set to "Next" for first two lines 
    // and "Done" for the last line, so jump to the next text field 
    NSLog(@"\"Return\" key pressed."); 

    // based on which text field we are in jump to the next 
    if (textField.tag == Line3Tag) 
     // We have reach the last line so hide keyboard 
     [textField resignFirstResponder]; 

     // this is where you can perform Core Data updates if you like 

    else { 
     int nextTag = textField.tag + 1; 
     UIView *nextField = [self.view viewWithTag:nextTag]; 
     [nextField becomeFirstResponder]; 

     // Once the next text field is the first responder 
     // I need to make sure the user can see it 
     [self makeActiveTextFieldVisible]; 
    } 
    return NO; 
} 
+0

謝謝,它works.but stackoverflow.com不能讓我sumbit新頁面 – 2011-04-18 06:01:14

相關問題