我有一个UICollectionViewController
,我试图将UIView添加为集合视图的标题视图。我目前的尝试是在经过大量时间跟踪大量指南后没有显示UIView。我希望有人能指出我正确的方向。
我目前的做法:
Set height of supplemental view and register
ViewDidLoad(){
CollectionView.RegisterClassForSupplementaryView(typeof(CollectionHeader), UICollectionElementKindSection.Header, "HeaderView");
UICollectionViewFlowLayout layout = new UICollectionViewFlowLayout();
layout.HeaderReferenceSize = setHeader(this).Frame.Size; //setHeader returns a UIView
CollectionView.SetCollectionViewLayout(layout, true);
}
Gets the supplemental view
public override UICollectionReusableView GetViewForSupplementaryElement(UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
{
CollectionHeader headerView = (CollectionHeader)collectionView.DequeueReusableSupplementaryView(UICollectionElementKindSection.Header, "HeaderView", indexPath);
headerView.owner = this;
headerView.view = setHeader(this);//setHeader returns a UIView
return headerView;
}
Create my view via a class (not really sure how/why to do this)
public class CollectionHeader : UICollectionReusableView {
public UIView view {
get { return view; }
set { view = value; SetNeedsDisplay();}
}
public PhotographController owner;
[Export("initWithFrame:")]
public CollectionHeader(System.Drawing.RectangleF frame) :base(frame) {
view = new UIView(setHeader(owner).Frame);
AddSubview(view);
}
}
感谢您的帮助!