Siv*_*hen 1 objective-c uitableview layoutsubviews
当我使用带有类别的UItableViewcell的layoutSubviews方法时,就像下面的代码一样
@implementation UITableViewCell (forimage)
- (void)layoutSubviews{
[super layoutSubviews];
self.imageView.frame = CGRectMake(0, 0, 50, 50);
}
@end
Run Code Online (Sandbox Code Playgroud)
当我使用下面的代码绘制单元格时,textLabel消失了,任何人都知道为什么会这样〜,这是否意味着如果我使用layoutSubviews,我必须在方法中写下我需要的所有子视图?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
RadioInfo *radioinfo = [radios objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@",radioinfo._name];
if(!radioinfo._logo){
if(self.tableView.dragging == NO && self.tableView.decelerating == NO){
[self startPicDownload:radioinfo forIndexPath:indexPath];
}
cell.imageView.image = [UIImage imageNamed:@"1.jpg"];
}
else {
cell.imageView.image = radioinfo._logo;
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
你想要做的是添加UITableViewCell的layoutSubviews方法的行为,而不是替换它.
要正确添加行为,请将单元格子类化并执行您自己的布局,如上所述,但在方法顶部添加[super layoutSubviews]以确保首先执行单元格自己的基本布局.
| 归档时间: |
|
| 查看次数: |
7348 次 |
| 最近记录: |