2012-05-10 32 views
1

我使用自定義的表視圖來顯示從數據核心我的數據,它應該是這個樣子爲什麼tableview不顯示任何數據?

enter image description here

但我實際上已經得到的是這種

enter image description here

這是我的代碼:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return [[self.fetchedResultsController sections] count]; 
} 

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


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
    Item *item = [self.items objectAtIndex:indexPath.row]; 
    UILabel *nameLabel = (UILabel *)[cell viewWithTag:100]; 
    nameLabel.text = item.name; 
    UILabel *catLabel = (UILabel *)[cell viewWithTag:101]; 
    catLabel.text = item.category; 
    UILabel *amountLabel = (UILabel *)[cell viewWithTag:102]; 
    amountLabel.text = item.amount; 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"AccountCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    [self configureCell:cell atIndexPath:indexPath]; 

    return cell; 

} 

回答

1

您的其他數據源遇到你正在工作,因爲你可以看到有細胞存在,但沒有填充。

這條線:

Item *item = [self.items objectAtIndex:indexPath.row]; 

當您使用已取得的成果控制器不平常。它應該是

Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

如果您檢查調試器,您將看到該項目可能與您當前的代碼爲零。

如果不是這種情況,那麼您的標籤在原型單元格和代碼之間不匹配。再次,這可以在調試器中檢查 - 標籤將爲零。

+0

Thx mate,可以工作,但我仍然有問題,我已經改變了故事板中單元格的大小,但它不起作用,模擬器中單元格的大小仍然是默認大小,怎麼樣? – oratis

+0

更改故事板中表格視圖本身的行高度。雖然這應該可能是一個單獨的問題:) – jrturton

1

如果你右鍵單擊故事板中的標籤,你可以看到他們連接到什麼網點。檢查他們是否有白點表示連接,然後如@jhurton所示,檢查您的數據項是不是nil

相關問題