カスタム UITableViewCell を使用して、iOS アプリケーションの UITableView に結果を表示しようとしています。セルの textLabel プロパティと detailTextLabel プロパティを使用すると、配列の内容を表示できますが、UITableView をカスタム セル クラスにリンクして配列の内容を表示しようとすると、Interface からデフォルト値しか取得できません。テーブルにビルダーが表示されます。
これは私が持っている関連コードです:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
TransactionList *tList = [_list objectAtIndex:indexPath.row];
/*
cell.transaction.text = tList.transaction;
cell.type.text = tList.type;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"ddMMYYYY"];
NSString *dateAsString = [formatter stringFromDate:tList.date];
cell.date.text = dateAsString;
*/
//this code below displays the contents just fine, but the block of code above does not.
cell.textLabel.text = tList.transaction;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", tList.type, tList.status];
return cell;
}
以下のメソッドは、私の CustomTableCell クラスにあるものです。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.frame = CGRectMake(0, 0, 320, 80);
_transaction = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 80, 40)];
[_transaction setBackgroundColor:[UIColor clearColor]];
[_transaction setFont:[UIFont systemFontOfSize:12]];
[_transaction setNumberOfLines:2];
[_transaction setLineBreakMode:NO];
[self.contentView addSubview:_transaction];
_date = [[UILabel alloc] initWithFrame:CGRectMake(100, 5, 80, 40)];
[_date setBackgroundColor:[UIColor clearColor]];
[_date setFont:[UIFont systemFontOfSize:12]];
[_date setNumberOfLines:2];
[_date setLineBreakMode:NO];
[self.contentView addSubview:_date];
_type = [[UILabel alloc] initWithFrame:CGRectMake(200, 5, 80, 40)];
[_type setBackgroundColor:[UIColor clearColor]];
[_type setFont:[UIFont systemFontOfSize:12]];
[_type setNumberOfLines:2];
[_type setLineBreakMode:NO];
_type.lineBreakMode = NO;
[self.contentView addSubview:_type];
}
return self;
}
_transaction、_date、および _type はラベルです。MainStoryboard 内の Interface Builder のスクリーンショットを次に示します。
スタイルを「基本」から「カスタム」、「字幕」に変更しようとしましたが、解決しません。テーブルのデフォルト値のみが表示され、それらの設定は表示方法を変更しますが、配列の内容がテーブルに表示されることはありません。誰が私が間違っているのかを見ることができますか? 問題は単純なものだと本当に思いますが、残念ながら私はそれに指を置くことができません。
回答者全員に事前に感謝します。