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
。
一切都已完成,以完美地转换为字符串,但仍然为什么错误比较?
答案 0 :(得分:8)
删除尾部分号!
if ([fetchedtitle isEqualToString:oldTitle])
{
ann.title = appDelegate.pinTitle;
break;
}
使用分号,您的代码与:
相同if ([fetchedtitle isEqualToString:oldTitle])
;
{
ann.title = appDelegate.pinTitle;
break;
}
答案 1 :(得分:1)
由于IF语句末尾有一个分号,因此代码为:
if( [fetchedtitle isEqualToString:oldTitle])
{
// Do nothing
}
// this will always run
ann.title = appDelegate.pinTitle;
break;
答案 2 :(得分:1)
替换以下行
if([fetchedtitle isEqualToString:oldTitle]);
与
if([fetchedtitle isEqualToString:oldTitle])
答案 3 :(得分:1)
只需从代码的以下部分中删除分号(;)......
if([fetchedtitle isEqualToString:oldTitle]);