0

I am trying to get the height and some other attributes from a prototype UICollectionViewCell in my storyboard. I need those values in the ViewDidLoad, so before any cell is rendered.

I found this answer for tableview:
https://stackoverflow.com/a/14127936/2637259
But it doesn't seem to work for a collectionview because I need a indexpath.

I also found this answer which seems to solve the problem: https://stackoverflow.com/a/22761931/2637259
But I don't know how to do that in xamarin.

Can anyone enlighten me please?

Edit: The reason I need to have it at ViewDidLoad (or at least anywhere before the cells are loaded) is a UIWebView I have in the cell. I have a html string to load into the cell. So I made a function to calculate the height of the webview. After all cells are calculated I call CollectionView.ReloadData() to load the cells. In the sizeForItemAtIndexPath I need to check if the height of the cell is less than the height of the cell without the webview plus the calculated height of the webview. If not, I need to return the standard cell size. Else I need to return the cell height without the webview plus the calculated height.

Community
  • 1
  • 1
Superwayne
  • 1,146
  • 1
  • 12
  • 22

1 Answers1

0

You could just create static properties for you custom cell classes like this:

public partial class CustomCell: UICollectionViewCell
{

    public static new float CellHeight { get { return 44f; } }

    ... rest of your class

then you can get the height by just calling

CustomCell.CellHeight;

Hope that helps! Cheers!

yairsz
  • 438
  • 5
  • 15
  • That's what I am currently doing at the moment. But when someone else makes a change in the storyboard, the change would "brake" my code. Therefore I'm searching for a way to let other people change cells (there are many different cells in the project) without having to check each cells class. – Superwayne Apr 23 '15 at 19:07