2011-08-08 49 views
1

數據填充,但[tableView numberOfRowsInSection:0]總是返回0.我的表中只有一個部分。什麼類型的東西會導致這種行爲?[tableView numberOfRowsInSection:0總是返回0

+0

嘗試給它不同的數字,以查看哪個部分返回正確的行數 –

+0

沒有運氣,但0返回無效的數字錯誤.... – mdominick

+0

從0開始循環到'[tableView numberOfSections]'和NSLog()this語句與循環計數器作爲參數例如。 '[tableView numberOfRowsInSection:i]'我在哪裏你的循環計數器 –

回答

4

如果永遠只有一個部分表格,請用以下男女同校...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     return 1; 
    } 

或者如果你的段數取決於數據源,您可以返回您的數據源的數。

+0

嗯......我試圖得到一個段中的數字行,而不是在一個段中設置數字行。還是有什麼我在這裏失蹤? – mdominick

+0

@mdominick - 區段中的行數等於您爲區段返回的行數。因此你可能錯過了這個委託方法的要點。 –

+0

所以,我正在做的是[數據計數]。我也嘗試硬編碼一個實際的數字(就像你在樣本中做的那樣),雖然這個方法被稱爲值似乎變爲0 ... – mdominick

0
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; 
return [sectionInfo numberOfObjects]; 

試試這個。它可能會幫助你。