我使用自定義的表視圖來顯示從數據核心我的數據,它應該是這個樣子爲什麼tableview不顯示任何數據?
但我實際上已經得到的是這種
這是我的代碼:
- (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;
}
Thx mate,可以工作,但我仍然有問題,我已經改變了故事板中單元格的大小,但它不起作用,模擬器中單元格的大小仍然是默認大小,怎麼樣? – oratis
更改故事板中表格視圖本身的行高度。雖然這應該可能是一個單獨的問題:) – jrturton