2014-01-28 24 views
-3

檢查計我有WebService的問題,當web服務返回的字符串數據如何從字符串

if ([collectionView indexPathForCell:bookcell ].row == row) { 
if ([[[bookList objectAtIndex:row] mainMenu] isEqualToString:@"standard"]) { 

// [[bookList objectAtIndex:row] mainMenu]isEqualToString:@"standard"] have 5 row data 

} 
} 

我需要顯示NSlog(@"count %d",total)我怎麼能顯示總= 5,通常是會顯示count 1 5的時間,但我需要顯示count 5 1次請教我。

+0

我沒有看到一個'total'變量在這裏得到了字「標準」的總數。此外,我不知道你如何期望值'1'記錄爲'5'。你將不得不大量改善這個問題...... – nhgrif

回答

1

我想最簡單的事情就是統計你的數組「bookList」中有多少個對象具有文字標準。

static int counter = 0; //make this a global variable 

for (int i=0; i<[bookList count]; i++) 
{ 

    NSString *str1 = [bookList objectAtIndex:i]; 
    if ([str1 isEqualToString:@"standard"]) 
    { 
     counter++; 
    } 
} 

現在你從你的陣列