我们创建的tableView,有时候需要调整一下系统cell上的imageview的frame,直接在cell中重新设定frame是不行的,如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HMVideoCell *cell = [HMVideoCell cellWithTableView:tableView];
cell.imageView.frame = CGRectMake(0, 0, 100, 100);
cell.video = self.videos[indexPath.row];
return cell;
}
因为这个方法只负责创建cell,return cell的时候相当于又自动重新设定了frame
解决办法::
在 layoutSubviews 方法中设定 frame ;(但是还是需要创建一个cell类,不懂和自定义cell有什么区别,可能就省去了默认cell上创建imageview,textLable,
detailTextLabel这三个控件的代码吧)
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];(必须要调用super,否则会出现奇葩问题)
self.imageView.frame = CGRectMake(0, 0, 100, 100);
}
自此,问题解决