Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Some issues with UITableViewCell

$
0
0

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

        ContentView.AddSubview(userImage);
        ContentView.AddSubview(usernameLabel);
        ContentView.AddSubview(followButton);
    }
}

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.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>