次のコードで [cell addSubview: someLabel]
vsを実行[cell.contentView addSubview: someLabel]
すると、同じように動作するように見えます。どちらかを行う違いはありますか?(実際のコードのカスタム セルは and を追加UIImageView
していますUILabel
) (UIView
一方、 には がないcontentView
ため、その にサブビューを追加する必要はありませんcontentView
。 ちなみにUITableViewCell
は のサブクラスですUIView
)
-(UITableViewCell *) tableView:(UITableView *) tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if ([tableView isEqual:self.songsTableView]){
static NSString *TableViewCellIdentifier = @"MyCells";
cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableViewCellIdentifier];
}
// ... some code to create a UILabel (not shown here)
[cell addSubview: someLabel]; // vs using [cell.contentView addSubView: ...]