Ни один из моих методов UICollectionViewDelegateFlowLayout не вызывается. Может ли кто-нибудь помочь мне найти решение?UICollectionViewDelegateFlowLayout методы, не вызываемые в Swift 2.3 App
В моем методе ViewDidLoad, я поставил делегат и источник данных для представления коллекции в self.collectionView.delegate = self
и self.collectionView.dataSource = self
Вот мои методы делегата:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
let deviceIdiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom
switch(deviceIdiom){
case .Phone:
return UIEdgeInsets(top: 50, left: 10, bottom: 0, right: 10)
case .Pad:
return UIEdgeInsets(top: 60, left: 20, bottom: 0, right: 20)
default:
break
}
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return CGFloat(8)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let deviceIdiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom
switch(deviceIdiom){
case .Phone:
let cellWidth = (view.bounds.size.width - 16)/2
let cellHeight = cellWidth
return CGSize(width: cellWidth, height: cellHeight)
case .Pad:
let cellWidth = (view.bounds.size.width - 40)/2
let cellHeight = cellWidth
return CGSize(width: cellWidth, height: cellHeight)
default:
break
}
}
Мои ViewDidLoad ме-
переопределение func viewDidLoad() { super.viewDidLoad()
self.collectionView.dataSource = self
self.collectionView.delegate = self
cellImages = [
"contact.png",
"share.png",
"setting.png",
"logout.png"]
cellLabels = [
"Contact",
"Share",
"Setting",
"Logout"]
self.view.backgroundColor = uicolorFromHex(0xE5DADA)
self.collectionView?.backgroundColor = uicolorFromHex(0xE5DADA)
self.navigationController?.navigationBarHidden = false
self.navigationItem.hidesBackButton = true
navigationController!.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.whiteColor()]
navigationController!.navigationBar.barTintColor = UIColor(red: 0.0431, green: 0.0824, blue: 0.4392, alpha: 1.0)
if let user = User.currentUser(){
if(user.manager){
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Board", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(goToBoard))
}
Спасибо,
Установили ли вы контрольные точки и удостоверились, что их не называют? Если вы этого не сделали, возможно, что ваш коммутатор просто подходит к случаю по умолчанию. –
Опубликовать весь метод 'viewDidLoad' – Alistra
@BenjaminLowry Да, я установил контрольные точки. Спасибо, –