2013-02-19 196 views
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; 
    } 
} 

但是比較總是如此。可能是什麼錯誤?isEqualToString總是返回true

從sqlite獲取的const char被鑄造爲stringWithUTF8String

一切都已完成,以完美的鑄造字符串,但仍然爲什麼是比較錯誤?

回答

8

刪除尾部的分號!

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

隨着分號,你的代碼是一樣的:

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

LOL我多麼的愚蠢。非常感謝你的幫助... – Manoj 2013-02-19 13:06:52

+1

我們都去過那裏。 – trojanfoe 2013-02-19 13:07:19

+0

大聲笑,完全相同的錯誤..在此頁登陸.. – Kyuubi 2013-06-13 09:24:56

1

既然你在你的IF語句結尾有分號你的代碼是:

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

// this will always run 
    ann.title = appDelegate.pinTitle; 
       break; 
+0

感謝您的幫助 – Manoj 2013-02-19 13:10:40

1

替換以下行

if([fetchedtitle isEqualToString:oldTitle]); 

if([fetchedtitle isEqualToString:oldTitle]) 
+0

感謝您的幫助 – Manoj 2013-02-19 13:09:55

1

只是刪除分號(;)從你的代碼的以下部分...

if([fetchedtitle isEqualToString:oldTitle]);