0

いくつかのラベルと右端に 3 つのボタンを持つカスタム UITableViewCell があります。Storyboard のプロトタイプ セルを使用しました。表示は問題ありませんが、スワイプしてテーブルの行を削除すると、セルの内容の上に削除ボタンが表示されます。私はすでに2つのことを試しました。私が疑問に思っていることの 1 つは、デザイン時に Storyboard プロトタイプ セルで contentView を使用できないのはなぜですか?

さまざまな autoresizingMask UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;

コントロールは [self.contentView addSubview:self.buttonView] として contentView に追加されます。

カスタムセルの私のコードは、最初はhファイルと自動生成されたmファイルのIBOutletsだけで空でしたが、何も追加しませんでしたが、今はフォローしようとしましたが、違いはありません

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialize controls
        self.accountName.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.accountId.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.offerName.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.offerCode.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.createdDate.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.createdUser.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.orderValue.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.buttonInfo.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.buttonEdit.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
        self.buttonView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;

        // Add controls to Content View
        [self.contentView addSubview:self.accountName];
        [self.contentView addSubview:self.accountId];
        [self.contentView addSubview:self.offerName];
        [self.contentView addSubview:self.offerCode];
        [self.contentView addSubview:self.createdDate];
        [self.contentView addSubview:self.createdUser];
        [self.contentView addSubview:self.orderValue];
        [self.contentView addSubview:self.buttonInfo];
        [self.contentView addSubview:self.buttonEdit];
        [self.contentView addSubview:self.buttonView];
    }
    return self;
}

tableViewの私のコード

- (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"SavedOrderCell";

    if ([self.orders count] == 0) {
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        return cell;
    }
    else {
        SavedOrderCell *cell = (SavedOrderCell*)[tableView2 dequeueReusableCellWithIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.parentVC = self;

        [cell.buttonEdit addTarget: self action: @selector(editProduct:) forControlEvents: UIControlEventTouchUpInside];

        // Configure the cell.
        Order *order = (Order *)[self.orders objectAtIndex:indexPath.row];

        cell.accountName.text = order.orderAccount.name;
        cell.accountId.text = [NSString stringWithFormat:@"ID: %i", [order.orderAccount.accountId intValue]];
        cell.offerName.text = order.orderPromotion.name;
        cell.offerCode.text = order.orderPromotion.code;
        cell.createdDate.text = [NSDateFormatter localizedStringFromDate:order.createdDate dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle];
        cell.createdUser.text = order.createdUser;
        cell.orderValue.text = [Common getCurrencyFormattedStringFromNumber:order.orderTotal];

//        [cell.buttonStatus setImage:[UIImage imageNamed:[NSString stringWithFormat:@"status_%i", [order.statusId intValue]]] forState:UIControlStateNormal];

        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:cell.backgroundView.frame];
        bgImage.backgroundColor = [UIColor clearColor];
        bgImage.opaque = NO;

        if (indexPath.row == 0)
            bgImage.init.image = [UIImage imageNamed:@"table_1col_mid_top.png"];
        else
        {
            if (indexPath.row % 2) {
                bgImage.init.image = [UIImage imageNamed:@"table_1col_light.png"];
            }
            else{
                bgImage.init.image = [UIImage imageNamed:@"table_1col_mid.png"];
            }
        }

        cell.backgroundView = bgImage;

        return cell;
    }
}
4

2 に答える 2

0

そのテーブルビューはxibにありますか?? その場合、autosize プロパティを設定する必要があります。重複しないように設定します。autosize の上、下、右、および左のプロパティを設定すると、xib インスペクタで autosize 用に指定された画像に表示されます。

于 2013-08-14T09:17:53.330 に答える
0

プログラムで UI を実行している場合は、次のことを確認してください。

  1. セルのすべてのサブビューが contentView に追加されます
  2. すべての制約は contentView にリンクされています (セル自体ではありません)。
于 2019-02-13T22:03:51.503 に答える