在下面的代码中,如果我们使用 [cell addSubview: someLabel]vs [cell.contentView addSubview: someLabel],它们看起来是一样的。做一个或另一个有什么区别吗?(实际代码中的自定义单元格是添加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: ...]