单元数据不会更新

时间:2012-06-26 12:21:43

标签: objective-c ios xcode xcode4

我正在阅读一些教程,用于编辑其数据存储在服务器中的表格单元格。一切都运行正常 - 我可以编辑表格单元格并单击“保存”按钮,但如果我回到表格概述它不会更新。 我有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){并且我没有收到错误,但它并没有改变数据不会更新更改的事实。

上面的代码应该如何?

1 个答案:

答案 0 :(得分:2)

那些IF没有意义,你不能这样做:

if (titleField == authorField == atextField)

因为您要将第一个==的结果与文本字段进行比较,因此指针和整数错误之间的比较。

在第二个中,

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

这永远不会被调用,因为titleField不能同时是3件事。

我的第一个想法是做这样的事情:

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

我认为这就是你想要做的。