Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
like image 453
Anand Avatar asked Oct 31 '11 08:10

Anand


2 Answers

You need to set the table view's row height either in interface builder, in code in your view controller, or in the table view delegate method tableView:heightForRowAtIndexPath:

like image 121
jrturton Avatar answered Nov 11 '22 08:11

jrturton


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.

like image 27
Sulthan Avatar answered Nov 11 '22 07:11

Sulthan