2016-10-17 55 views
0

我在我的項目中使用了core data。我可以選擇在我的應用程序中添加汽車,並且我正在顯示增加的汽車在tableView fortunatly我已經添加了3行。當我打開我的應用程序時,我打電話給我的服務,我得到了45個數據。我必須將這3 tableview數據與45個數據進行比較。遞增索引獲取錯誤

這裏我創建了一個NSInteger totalCars變量。

這裏是我的代碼:

totCars = self.carSelectionManager.totalCars; 

,我通過將「指數= 0」靜態獲取第一行數據。

Car *car = [self.carSelectionManager carAtIndex:0]; 
[self.service getMakesForYear:car.year]; // with the help of first row data I am calling the service data. 

我正在獲取第一行數據。同樣我也想要其餘的第二和第三行數據。但我無法寫出任何人都可以幫助解決這個問題的邏輯。

在此先感謝。

回答

0

請嘗試:

for (Car * car in self.carSelectionManager){ 
    [self.service getMakesForYear:car.year]; 
} 

或者你可以試試這個:

if (carSelectionManager){ 
    for (int i = 0 ; i < [self.carSelectionManager count];i++){ 
    Car *car = [self.carSelectionManager carAtIndex:0]; 
    [self.service getMakesForYear:car.year]; 
    } 
} 
+0

我得到這個警告「集合表達式類型 'CarSelectionManager *' 不能爲「countByEnumeratingWithState迴應:對象:數: 「」。 CarSelectionManager是一個類。 –

+0

增加功能對車輛數進行計數,並將其分類 表示:增加新車增量計數器時,並返回計數功能。 – Bassam

+0

它不工作。 –