在单色中调整自定义UITableViewCell的大小

本文关键字:UITableViewCell 自定义 单色中 调整 | 更新日期: 2023-09-27 18:29:38

我只想增加单个单元格的高度。我增加了IB和代码的高度,但两者似乎都不起作用。Poicell是我的自定义uitableviewcell的类。以下是我的代码:

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;
}

在单色中调整自定义UITableViewCell的大小

您必须重写GetHeightForRow方法并返回您希望每行具有的高度。

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

尝试添加:

cell.SetNeedsDisplay();

就在你还牢房之前。我相信这就是我必须要做的,才能让它发挥作用。