2016-08-13 3 views
0

Я хочу добавить нижний колонтитул в UICollectionView, используя этот код. Я использую Использование пользовательского макета в макет UICollectionViewUICollectionview footer in swift

Добавлен делегат и DataSource методы: -

UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout

Код в viewdDidLoad() функции: -

UINib(nibName: "ProfileFooter", bundle:nil) 
collectionView!.registerNib(nibName1, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter") 
     collectionView.registerClass(ProfileFooter.classForCoder(), forSupplementaryViewOfKind: "ProfileFooter", withReuseIdentifier: "ProfileFooter") 

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 

     var reusable = UICollectionReusableView() 

      if kind == UICollectionElementKindSectionFooter{ 
       let ProfileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath) 
       ProfileFooter.backgroundColor = UIColor.redColor() 
       reusable = ProfileFooter 
      } 

     return reusable 
    } 

может любой проверить, что случилось в это ??

+0

Почему вы написали как registerNib, так и registerClass? удалите строку registerNib. –

+0

Я проверил, что оба они все еще не работают ... – Ravi

+0

Запишите строку registerClass следующим образом: 'registerClass (ProfileFooter, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier:« ProfileFooter »)', а также еще раз проверить идентификатор нижнего колонтитула правильно или нет , –

ответ

1

Вы забыли бросить свой нижний колонтитул во время dequeuing. Попробуйте это.

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 
switch kind 
{ 
    case UICollectionElementKindSectionFooter: 
     let profileFooter = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "ProfileFooter", forIndexPath: indexPath) as! ProfileFooter 
     profileFooter.backgroundColor = UIColor.redColor() 
     return profileFooter 
    case default: 
     assert(false, "Unexpected element kind") 
} 
} 
+0

Я использую пользовательский макет в коллекции. – Ravi

+0

Не могли бы вы более подробно рассказать о том, что не работает в вашем коде. Я узнал, что нижний колонтитул не бросается. Если бы вы могли предоставить более подробную информацию, это было бы полезно! –

Смежные вопросы