2013-03-20 114 views
-2

我是新開發人員並創建了for循環。但是,'for'循環值不會增加。Objective-C for循環失敗

這裏是我的代碼:

int j=0; 
for (int i=0; i < localDocuments.count; i++) { 
    if(j<imageList.count){ 
     for (j=0; j<=i;j++) { 
      NSURL * fileURL = [localDocuments objectAtIndex:i]; 
      NSString *str=[NSString stringWithFormat:@"%@.%@",[imageList objectAtIndex:j],PTK_EXTENSION]; 
      if ([[fileURL lastPathComponent] isEqualToString:str]){ 
       [self loadDocAtURL:fileURL]; 
      }//if 
     }//for j 
    }//if 
}//for i 

iif ([[fileURL lastPathComponent] isEqualToString:str])條件失敗不會增加。

當字符串值不相等時,循環不會跳到下一個文件url。

任何人都可以發現我的錯誤嗎?

+0

不下來投票我想要解決方案,如果你知道幫助我 – Vijay 2013-03-20 12:28:06

+1

謝謝@Anzeo進行編輯,這是有道理的。 – Popeye 2013-03-20 12:30:25

+0

'NSLog()''[fileURL lastPathComponent]'和str – Popeye 2013-03-20 12:32:29

回答

0

在嵌套循環(j)中,我不會增加。此外,你應該考慮重新J即可0(我真的不明白if(j<imageList.count)條件..它應該是imageList.count > 0?)

0

至於你說:

沒有我想要的我= 0,J = 0,1,2,3 ,,,然後我= 1,J = 0,1,2,3 ,,,,這樣

您應該使用

for (j=0; j<localDocuments.count;j++) { 
+0

我有疑問請我想加載選擇的圖像列表,這是在localdocument這裏什麼樣的聲明,我們將用於循環或while循環 – Vijay 2013-03-20 12:48:12

+0

在一個文件夾中?然後簡單地使用快速枚舉並使用每個元素。 – 2013-03-20 12:52:55

+0

我不知道快速枚舉概念,請幫助我,並提供一些有用的參考 – Vijay 2013-03-20 12:57:21