Can´t add items to UICollectionView inside UIView xib

后端 未结 5 1769
说谎
说谎 2021-02-05 09:20

Objective

I wanna place my (BusinessViewTableHeader: UIView) as tableView header:

tableView.tableHeaderView = BusinessViewTableHeader.instanceFromNib() a         


        
5条回答
  •  一整个雨季
    2021-02-05 09:50

    Adding cells in a xib is not supported. If you must use a xib file, then you will need a separate xib which contains the UICollectionView cell. Storyboards may be a better solution.

    It is not clear what you are trying to achieve. UICollectionView has specific means for creating headers which uses the datasource and delegate. Collection views are good for displaying items in a grid layout or other complex arrangements.

    If all you need is to display a list of rows, then a UITableViewController might be an easier alternative.

    Whatever the case, it is probably better to use a storyboard instead of a xib, and to subclass the UICollectionViewController or UITableViewController, rather than a subview.

    Your custom class name can be entered in the identity inspector for the UIViewController or UIView:

提交回复
热议问题