简体   繁体   English

自定义表视图单元格未按照笔尖调整大小

[英]Custom Table view cell not resizing as per nib

I created a new custom TableViewCell by subclassing UITableViewCell. 我通过继承UITableViewCell创建了一个新的自定义TableViewCell。 I created a table view with UIImage view using a nib and I hooked it with view's outlets. 我使用笔尖创建了一个带UIImage视图的表视图,并将其与视图的出口挂钩。 Then while populating the table from my TableView delegate, I used the subclass for return table view cells. 然后在从TableView委托填充表时,我使用子类来返回表视图单元格。

New content from the nib is getting loaded. 来自笔尖的新内容正在加载。 But the new size of custom table view cell (i resized the table view cell to a new large size) is not getting loaded in the table view. 但是,自定义表视图单元格的新大小(我将表格视图单元格调整为新的大尺寸)未在表格视图中加载。

Am I missing some call during the rendering? 我在渲染过程中错过了一些电话吗? Please help 请帮忙

@interface AccountOption : UITableViewCell
{
    IBOutlet UIImageView* optionIcon;
}

@property (nonatomic, retain) IBOutlet UIImageView* optionIcon;

@end

In delegate, 在代表中,

  NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AccountOption" owner:nil options:nil];


    for (id currentCell in topLevelObjects) {
        if ([currentCell isKindOfClass:[AccountOption class]]) {
            cell = currentCell;
        }
    }




cell.optionIcon.image = [(NSDictionary*)[accountOptions objectAtIndex:indexPath.row] objectForKey:@"icon"]; 
return cell;

您需要在界面构建器中,在视图控制器的代码中或在表视图委托方法tableView:heightForRowAtIndexPath:设置表视图的行高tableView:heightForRowAtIndexPath:

Size of a cell is defined by its UITableView. 单元格的大小由其UITableView定义。 The table has a property and a delegate method which define cell (row) height. 该表有一个属性和一个委托方法,用于定义单元格(行)高度。 Cell width is always equal to the width of the table. 单元格宽度始终等于表格的宽度。 You can try to resize the cell manually but it will be always overwritten by the table. 您可以尝试手动调整单元格的大小,但它将始终被表格覆盖。

The height property is [UITableView rowHeight] and it is preferred over setting the height by table delegate method tableView:heightForRowAtIndexPath: . height属性是[UITableView rowHeight] ,它优先于表委托方法tableView:heightForRowAtIndexPath:设置高度。 The delegate method should be used only when you need different cells to have different height. 只有当您需要不同的单元格以具有不同的高度时,才应使用委托方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM