2012-03-30 72 views
4

我想要做的就是增加單個單元格的高度。我已經提高了IB和我的代碼的高度,但都似乎沒有工作。 Poicell是我的自定義uitableviewcell的類。以下是我的代碼:在Monotouch中調整自定義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; 

} 

回答

6

您必須重寫GetHeightForRow方法並返回每行所需的高度。

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

嘗試增加:

cell.SetNeedsDisplay(); 

返回小區權利之前。我相信這是我必須做的才能實現它的工作。

相關問題