Изменение размера пользовательского UITableViewCell в Monotouch - PullRequest
4 голосов
/ 30 марта 2012

Все, что я хочу сделать, это увеличить высоту отдельных ячеек.Я увеличил высоту в IB и в моем коде, но оба, похоже, не работают.Poicell - это класс для моей пользовательской ячейки uitableview.Вот мой код:

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;

}

Ответы [ 2 ]

6 голосов
/ 30 марта 2012

Вы должны переопределить метод GetHeightForRow и вернуть высоту, которую вы хотите иметь для каждой строки.

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
    return 50f;
}
1 голос
/ 30 марта 2012

Попробуйте добавить:

cell.SetNeedsDisplay();

прямо перед возвратом ячейки.Я считаю, что это то, что я должен был сделать, чтобы заставить его работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...