0

デバッガーがこのエラーをスローしました

UITableView dataSourceからする必要がありreturnますcelltableView: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;
}

エラーを見つけることができないようで、新鮮な目を使うことができました。

4

2 に答える 2

4

cell内部に設定されることはありませんcase LOCATION_SECTION:

また、ブロックcell.textLabel.text内の値を設定して、後でそれをリセットする場合もあります。確かにこれは意図されていませんか?casenilcell.textLabel.text = text

于 2010-03-02T18:26:38.103 に答える
-1

さて、今私はばかげていると感じています。LOCATION_SECTIONの場合のセルのデキューを含む重要なコードスニペットを省略したようです。追加するとエラーがなくなりました。前回の「cell.textlabel.text=text;」のコードに残したものを指摘してくれた「rpetrich」に感謝します。これも削除する必要がありましたが、だからありがとう。

于 2010-03-02T22:20:43.773 に答える