2
for (Annotation *ann in annotaionArray) // annotationArray contains annotations added to map
{
    NSString *fetchedtitle = ann.title;

    if([fetchedtitle isEqualToString:oldTitle]); // oldTitle = textfield.text
    {
        ann.title = appDelegate.pinTitle;
        break;
    }
}

但比较总是正确的。请问可能是什么错误?

从 sqlite 获取的 const char 被强制转换为stringWithUTF8String.

一切都已完成以完美地转换为字符串,但仍然为什么比较错误?

4

4 回答 4

8

去掉后面的分号!

if ([fetchedtitle isEqualToString:oldTitle])
{
    ann.title = appDelegate.pinTitle;
    break;
}

使用分号,您的代码与以下内容相同:

if ([fetchedtitle isEqualToString:oldTitle])
    ;
{
    ann.title = appDelegate.pinTitle;
    break;
}
于 2013-02-19T13:01:28.463 回答
1

由于您的 IF 语句末尾有一个分号,因此您的代码是:

if( [fetchedtitle isEqualToString:oldTitle])
            {
            // Do nothing
            }

// this will always run
  ann.title = appDelegate.pinTitle;
                break;
于 2013-02-19T13:03:28.897 回答
1

只需从代码的以下部分中删除分号(;)...

if([fetchedtitle isEqualToString:oldTitle]); 
于 2013-02-19T13:13:18.640 回答
1

替换以下行

if([fetchedtitle isEqualToString:oldTitle]);

if([fetchedtitle isEqualToString:oldTitle])
于 2013-02-19T13:05:01.920 回答