2012-06-26 92 views
0

我正在閱讀一些教程,用於編輯其數據存儲在服務器中的表格單元格。一切工作正常 - 我可以編輯表格單元格,然後單擊「保存」按鈕,但如果我回到表格概述,它不會更新。 我有3表中的字段:單元格數據不更新

  • titleField
  • authorField
  • atextField

我不知道,如果問題來自於這一段代碼,但我想是這樣。本教程例子中只有2場,我需要3場,但我不知道如何實現這段代碼3個文本框:

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    if (textField == titleField) { 
     [authorField becomeFirstResponder]; 
    } 
    if (titleField == authorField) { 
     [self save]; 
    } 
    return YES; 
} 

我已經嘗試過if (titleField == authorField == atextField),但錯誤信息說:Comparison between pointer and integer ('int' and 'UITextField') 。我也嘗試過if (titleField == authorField && titleField == atextField && authorField == atextField){,我沒有收到錯誤,但它並沒有改變數據不會更新更改的事實。

上面的代碼應該如何顯示?

回答

2

那些IF的不要有感覺,你不能做到這一點:

if (titleField == authorField == atextField) 

因爲你是比較第一==與文本框,因此指針和整數誤差之間的比較結果。

在第二屆一個,

if (titleField == authorField && titleField == atextField && authorField == atextField) 

這是永遠不會被調用,因爲titleField不能在同一時間三兩件事。

我首先想到的會做這樣的事情:

if (textField == titleField) { 
      [authorField becomeFirstResponder]; 
     } 
    else if ((textField == authorField){ 
      [atextField becomeFisrtResponder]; 
    else if (titleField == atextField) { 
      [self save]; 
     } 

我想這是你想要做什麼。

+0

謝謝,我明白你的意思了!不幸的是,它仍然不能解決我的問題。所以這個問題可能是我想的其他地方。不管怎麼說,多謝拉。 – Kirinriki

相關問題