قالب وردپرس درنا توس
Home / IOS Development / Can anyone help me get a self-serve collection view to appear as a table header? : iOSProgramming

Can anyone help me get a self-serve collection view to appear as a table header? : iOSProgramming



I'm really struggling here. I remember UITableView.tableHeaderView as a source of problems when I first entered the iOS development in 2014. 5 years later, here we are – nothing has changed.

Basically, I want something like this, except that I just want a label in each cell, and I want the label + strip below it to determine the size of the cell. Unfortunately, the code used to make it not so useful because a) it uses automatic resizing masks for some parts of the control, and b) it requires you to specify the control height explicitly.

No matter how I set up my code, it always results in zero height control. It is posted as follows:

  • A UIControl subclass is the peak level display used as a table header display

  • a UICollectionView is inside the control, with all edges attached to its monitor the control

  • each cell has all edges of the label / strip attached to contentView except the bottom of the label and the top of the strip attached to each other

I have done what I thought were all necessary steps for this to work: [19659004] Return YES for requiresConstintBasedLayout in all subclasses (control and cell)

  • layout.itemSize = UICollectionViewFlowLayoutAutomaticSize

  • layout.estimatedItemSize = CGSizeMake (nonzero, nonzero);

  • Disabled translatesAutoresizingMaskIntoConstraints for all views involved, except cells contentView ] s and the table view of course

  • Implem ent updateConstraints in the control to pinch the collection view to itself on all pages

  • Implement updateConstraints in the cell class to pin on all subviews

  • Set the table view top view to the control in loadView

  • I tried even things I did not know I needed to do / things that are not clear are needed in the documents:

    • Point controller center width and top anchor to it in its monitoring

    • Manually insert the frame of the controller. format ] systemLayoutSizeFittingSize: UILayoutFittingCompressedSize on the control, and then set it as header view again

    • Implement preferredLayoutAttributesFittingAttributes: in the cell class [19659007] Here are links to relevant files / lines. The repo is here on the branch stash .

      To test it, start the UICatalog app and tap the globe icon in the FLEX window. The background to the control is set to redColor so it should be very clear when the control is actually displayed.

      Any help is appreciated 🙂 Thanks in advance


    Source link