调试器向我抛出了这个错误
UITableView dataSource
必须从return
_cell
tableView:cellForRowAtIndexPath:
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
NSString *text = nil;
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
switch (section)
{
case PURCHASE_SECTION:
{
static NSString *cellID = @"GenericCell";
cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
switch (row)
{
case CATEGORY_ROW:
text = [self.purchase.category valueForKey:@"name"];
cell.textLabel.text = text;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case TYPE_ROW:
text = [self.purchase.type valueForKey:@"name"];
cell.textLabel.text = text;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case VENDOR_ROW:
text = [self.purchase.vendor valueForKey:@"name"];
cell.textLabel.text = text;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
case NOTES_ROW:
text = @"Notes";
cell.textLabel.text = text;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
break;
default:
break;
}
break;
}
case ITEMS_SECTION:
{
NSUInteger itemsCount = [purchase.items count];
if (row < itemsCount)
{
static NSString *itemsCellID = @"ItemsCell";
cell = [tableView dequeueReusableCellWithIdentifier:itemsCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:itemsCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
PurchaseItem *item = [items objectAtIndex:row];
cell.textLabel.text = item.name;
cell.detailTextLabel.text = [item.amount formattedDataDisplay];
}
else
{
static NSString *AddItemCellID = @"AddItemCell";
cell = [tableView dequeueReusableCellWithIdentifier:AddItemCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:AddItemCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = @"Add Item";
}
break;
}
case LOCATION_SECTION:
{
text = @"Purchase Location";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.editingAccessoryType = UITableViewCellAccessoryNone;
break;
}
default:
break;
}
cell.textLabel.text = text;
return cell;
}
我似乎无法发现错误,我可以用一组新鲜的眼睛。