0

こんにちは、UITableViewCell をカスタマイズする必要があります。したがって、カスタム クラスとそれをサポートするために必要な UI (xib) を作成しました。XIB の場合、作成した派生クラスとしてクラスを選択しました。私の問題は、表示ラベルをプロパティにリンクした後、実行時に値を設定しても目的のテキストが表示されない場合です。空白のままにします。以下はコードスニペットです。

@interface CustomCell : UITableViewCell
{
    IBOutlet UILabel *titleRow;
}

@property (nonatomic, strong) UILabel *titleRow;
@property (nonatomic, strong) UILabel *subTitleRow;
@property (nonatomic, strong) UILabel *otherTextRow;
@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MedVaultCell";
    CustomCell *cell = nil;
    cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    if (nil == cell){

        //Load custom cell from NIB file
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellHistoryCell" owner:self options:NULL];
        cell = [nib objectAtIndex:0];

        //cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }   

    // get the object
    Weight *currentCellWeight = [_weights objectAtIndex:indexPath.row];

    // Configure the cell...
    UILabel *titleLable = [[UILabel alloc]init];
    titleLable.text = currentCellWeight.customDispText;
    [cell setTitleRow:titleLable];

    cell.titleRow.text = currentCellWeight.display;
    cell.titleRow.textColor = [UIColor redColor];
    //cell.textLabel.text = [[_weights objectAtIndex:indexPath.row] customDispText];
    //cell.textLabel.textColor = [UIColor whiteColor];


    return cell;
}
4

1 に答える 1

0

まず、カスタム セル クラスではなく、にあることを願っていcellForRowAtIndexPathます。UITableView delegate

第二に、ここに問題があります:

// Configure the cell...
UILabel *titleLable = [[UILabel alloc]init];
titleLable.text = currentCellWeight.customDispText;
[cell setTitleRow:titleLable];

このコードでは、新しいラベルを作成し、IBOutlet ラベルを新しいラベルでオーバーライドしています。次に、新しいラベルを表示していません。代わりに、コードを次のように変更します。

// Configure the cell...
cell.titleRow.text = currentCellWeight.customDispText;

ただし、その後のtitleRow.text右を にリセットしcurrentCellWeight.displayます。

そのため、テキストにしたいものを選択し、それにテキストを設定する必要があります。UILabel *titleLable = [[UILabel alloc] init];IB ですでにラベルを作成しているため、新しいラベル ( ) を作成する必要はありません。

于 2012-08-13T18:39:56.530 に答える