collectionView页脚没有显示

时间:2015-08-15 10:07:25

标签: ios swift

我已经检查了dataSource,如下面的屏幕截图所示。

collectionViewAttributesInspector

我还实现了 override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { if kind == UICollectionElementKindSectionHeader { var header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath) as? DetailHeader if header == nil { header = DetailHeader() } return header! } else { println("footer") var footer = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Footer", forIndexPath: indexPath) as! UICollectionReusableView return footer } } 方法:

println

我能够显示我的标题,但我的页脚从未显示过。 private final HibernateBundle<RestStubConfig> hibernate = new HibernateBundle<RestStubConfig>(Hotel.class) { public DataSourceFactory getDataSourceFactory(RestStubConfig configuration) { return configuration.getDataSourceFactory(); } }; public static void main(String[] args) throws Exception { new ServerStart().run(args); } @Override public void run(RestStubConfig restConf, Environment env) throws Exception { final HotelResource hotel = new HotelResource(); env.jersey().register(hotel); } @Override public void initialize(Bootstrap<RestStubConfig> bootstrap) { bootstrap.addBundle(hibernate); } 永远不会触发。

2 个答案:

答案 0 :(得分:4)

  1. 故事板的屏幕截图: enter image description here
  2. 2.我的代码:

    import UIKit
    
    class BaseCVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    
        override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    
            let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cvcCell", forIndexPath: indexPath)
    
            return cell;
        }
    
        override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return Int(2)
        }
    
        func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
    
            return CGSizeMake(self.view.frame.size.width, 20)
        }
    
        override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
    
            if kind == UICollectionElementKindSectionHeader {
                let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "header", forIndexPath: indexPath)
    
                return header
    
            } else {
                print("footer")
                let footer = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "footer", forIndexPath: indexPath)
                return footer
            }
        }
    }
    
    1. 模拟器中的结果:
    2. enter image description here

      1. 重要提示:我使用过Xcode 7 beta 5(Swift 2.0)

答案 1 :(得分:2)

选项1 :将footerReferenceSize上的UICollectionViewDelegateFlowLayout设置为大于0

选项2 :在您collectionView(_:layout:referenceSizeForFooterInSection:) 中实施UICollectionViewDelegateFlowLayout功能。