残念ながら、ドキュメントでも簡単な解決策(プロパティの設定など)は見つかりませんでした。そのため、自分でラベルを作成する必要がありましたが、元のセルを可能な限り使用し (たとえば、 を使用detailTextLabel
)、できるだけオリジナルに近いラベルをデザインしようとしました。これが私のコードです:
#define MASTER_LABEL_TAG 100
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *masterLabel;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
masterLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 8.0, 195.0, 48.0)];
masterLabel.tag = MASTER_LABEL_TAG;
masterLabel.font = [UIFont boldSystemFontOfSize:17];
masterLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0];
masterLabel.numberOfLines = 2;
[cell.contentView addSubview:masterLabel];
}
else
{
masterLabel = (UILabel *) [cell.contentView viewWithTag:MASTER_LABEL_TAG];
}
masterLabel.text = @"Something goes here";
return cell;
}
これが他の誰かにも役立つことを願っています。