简体   繁体   中英

Resizing Custom UITableViewCell in Monotouch

All I want to do is increase the height of the individual cells. I've increased the height in IB and in my code but both don't seem to be working. Poicell is the class for my custom uitableviewcell. The following is my code:

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
            var cell = tableView.DequeueReusableCell(kCellIdentifier) as PoiCell;   

            if (null == cell) {

                cell = new PoiCell();

                var views = NSBundle.MainBundle.LoadNib("PoiCell", cell, null);

                cell = Runtime.GetNSObject(views.ValueAt(0)) as PoiCell;
            }
            UIImage imgAmenity = UIImage.FromBundle ("Images/ico-ConservationGarden");
            UIImage imgRestrooms = UIImage.FromBundle ("Images/ico-restrooms");

            RectangleF rectCell = cell.Frame;
            rectCell.Height = 50;

            cell.Frame = rectCell;
            var imageView = new UIImageView(imgAmenity)
            {
                Frame = new Rectangle(10, 24, 20, 20)   
            };
            var imageView2 = new UIImageView(imgRestrooms)
            {
                Frame = new RectangleF(30, 24, 20, 20)  
            };
            cell.ContentView.Add(imageView);
            cell.ContentView.Add(imageView2);

            cell.Title = _poiFilterController.Posts[indexPath.Row].Title;
            cell.Distance = _poiFilterController.Posts[indexPath.Row].Distance;
            cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton;

            return cell;

}

You have to override the GetHeightForRow method and return the height you want each row to have.

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
    return 50f;
}

Try adding:

cell.SetNeedsDisplay();

right before you return the cell. I believe this is what I had to do to get it to work.

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