Some issues with UITableViewCell

Hi all,

I'm currently creating a table view which has a very custom layout and running in to several problems.

Firstly, the cell has a button which is to be used to select the row. Therefore I have set No selection in XCode for the table view. Then on click of the button I am manually setting Selected = true. This then makes the SelectedBackgroundView appear, however the background is covering most of the content. See the image below, the selected version is on the right.

Here's the code:

public class UsersCollectionCell : UITableViewCell
    public static string Identifier = "UsersCollectionCell";

    private UIImageView userImage;
    private UILabel usernameLabel;
    private UIButton followButton;

    public UsersCollectionCell()
        // selection view
        var selectionBackgroundView = new UIView();
        selectionBackgroundView.BackgroundColor = UIColor.Red; // red for testing
        SelectedBackgroundView = selectionBackgroundView;

        // user image
        userImage = new UIImageView(new RectangleF(9, 10, 29, 100));
        userImage.BackgroundColor = UIColor.Gray;

        // user name
        usernameLabel = new UILabel(new RectangleF(45, 13, 200, 20));
        usernameLabel.Font = UIFont.FromName("OpenSans", 13.0f);
        usernameLabel.TextColor = UIColor.FromRGB(54, 61, 65);

        // follow button
        followButton = new SmallRoundedRectButton(new RectangleF(225, 9, 84, 28));
        followButton.TouchUpInside += (object sender, EventArgs e) => {
            Selected = !Selected;


Also, I am setting the height of rows by subclassing UITableViewSource and overriding GetHeightForRow:

public class UsersCollectionSource : UITableViewSource
    public override float GetHeightForRow(UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
        return 227.0f; // this will eventually be dynamic

This works. However in the UITableViewCell itself how do I get the height? Bounds.Size.Height always return 44. As does the Frame. Why is this?

Finally, How can I determine which rows have been selected within the UITableView and pass this information back to the parent UIView so that I can use it before PerformSegue happens?

Thanks in advance for any help.


  • BenHoganBenHogan GBMember

    I've now changed the view to use UIViews within a UIScrollView and have a working (although ugly) solution. However I'd still be interested in hearing what the fixes for the above problems are for future reference.

  • SebastienPouliotSebastienPouliot CAXamarin Team Xamurai

    This is how the selection of UITableViewCell behave, see this SO Q&A for how you can workaround this.

Sign In or Register to comment.