简体   繁体   中英

Custom Table view cell not resizing as per nib

I created a new custom TableViewCell by subclassing UITableViewCell. I created a table view with UIImage view using a nib and I hooked it with view's outlets. Then while populating the table from my TableView delegate, I used the subclass for return table view cells.

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. 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: . The delegate method should be used only when you need different cells to have different height.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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