1

にあるUICollectionViewがあります。セルは、コレクションビューのデリゲートとデータソースです。すべてがストーリーボードに設定されています。セルはnumberOfItemsInSectioncellForItemAtIndexPathのメソッドを実装しており、これらのメソッドは常に正常に呼び出されます。また、セルはsizeForItemAtIndexPathのようなUICollectionViewDelegateFlowLayoutプロトコルのメソッドを実装します。これらのメソッドは決して呼び出されません。その理由は何でしょうか?迅速なバージョンに応じUICollectionViewDelegateFlowLayoutメソッドが呼び出されなかった

class SignUpFollowCategoriesCell : UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout 
{ 

@IBOutlet weak var categoryCollection: UICollectionView! 
@IBOutlet weak var categoryLabel: UILabel! 
@IBOutlet weak var followButton: UIButton! 

func setChosen(chosen:Bool) 
{ 
    followButton.checked = chosen 
} 

var category:Category? 
{ 
    didSet 
    { 
     guard let confirmedFollowButton = self.followButton else 
     { 
      return 
     } 
     confirmedFollowButton.hidden = true 
     guard let category = self.category else 
     { 
      return 
     } 
     guard let controller = self.controller else 
     { 
      return 
     } 
     guard let sites = controller.allSites[category.id] else 
     { 
      return 
     } 
     confirmedFollowButton.hidden = sites.count == 0 
    } 

} 
weak var controller:SignUpFollowCategoriesController? 

func setupWithController(control:SignUpFollowCategoriesController) 
{ 
    controller = control 
    guard let tmp = followButton else 
    { 
     return 
    } 
    tmp.addTarget(self, action: #selector(SignUpFollowCategoriesCell.clicked), forControlEvents: .TouchUpInside) 
    followButton.setStyleOptions(false, style: .ClearBackground, title: "+ Follow All") 
    followButton.setStyleOptions(true, style: .YellowBackground, title: "Following") 

} 

func clicked() 
{ 
    guard let control = controller else 
    { 
     return 
    } 
    guard let cat = category else 
    { 
     return 
    } 
    if control.categoryIsChosen(cat) 
    { 
     self.setChosen(false) 
     control.unfollowCategory(cat) 
    }else 
    { 
     self.setChosen(true) 
     control.followCategory(cat) 
    } 
    categoryCollection.reloadData() 

} 

private func updateFollowBtnStyle() 
{ 
    guard let control = controller else 
    { 
     return 
    } 
    guard let cat = category else 
    { 
     return 
    } 
    if control.categoryIsChosen(cat) 
    { 
     self.setChosen(true) 
    }else 
    { 
     self.setChosen(false) 
    } 
} 

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int 
{ 
    if let tmp = self.category 
    { 
     if let sites = controller?.allSites[tmp.id] 
     { 
      return sites.count 
     } 
    } 

    return 0; 
} 


private func firstLetterCaps(str : String) -> String 
{ 
    var ret = str 
    ret.replaceRange(str.startIndex...str.startIndex, with: String(str[str.startIndex]).capitalizedString) 
    return ret 
} 

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell 
{ 

    if let cell:SignupCategorySiteCell = collectionView.dequeueReusableCellWithReuseIdentifier("SignUpCategoryCollectionCell", forIndexPath: indexPath) as? SignupCategorySiteCell 
    { 
     cell.imageView.image = UIImage.imageWithColor(UIColor.slangBlueLight()) 
     var slangSite : SlangSite? 

     if let tmpID = self.category?.id 
     { 
      let sites = controller?.allSites[tmpID] 

      if let site = sites![indexPath.row] as SlangSite? 
      { 
       if let url = site.details.siteProfileImageURL() 
       { 
        cell.imageView.af_setImageWithURL(url) 
       } 

       let siteName = firstLetterCaps(site.details.siteName) 
       cell.siteNameLabel.text = siteName 

       slangSite = site 
      } 
     } 
     if let control = controller,let site = slangSite 
     { 
      if control.siteIsChosen(site) 
      { 
       cell.followStyle() 
      } 
      else 
      { 
       cell.unfollowStyle() 
      } 
     } 
     cell.onCellClickedBlock = {[weak self,controller] in 
      if let site = slangSite, let control = controller 
      { 
       if control.siteIsChosen(site) 
       { 
        cell.unfollowStyle() 
        control.unfollowSite(site) 
       } 
       else 
       { 
        cell.followStyle() 
        control.followSite(site) 
       } 
       self?.updateFollowBtnStyle() 
      } 
     } 
     return cell 
    } else 
    { 
     collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "DebugCell") 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("DebugCell", forIndexPath: indexPath) 
     cell.backgroundColor = UIColor.greenColor() 
     return cell 
    } 
} 

func collectionView(collectionView: UICollectionView, 
         layout collectionViewLayout: UICollectionViewLayout, 
          sizeForItemAt indexPath: NSIndexPath) -> CGSize 
{ 
    return CGSizeMake(92, 112) 
} 

func collectionView(collectionView: UICollectionView, 
         layout collectionViewLayout: UICollectionViewLayout, 
          insetForSectionAt section: Int) -> UIEdgeInsets { 
    return UIEdgeInsetsZero 
} 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { 
    return 100.0 
} 
} 
+0

あなたがコードを提供することができますか? –

+0

@EmrahAkgül確かに。どのようなコードを見たいのですか? –

+0

カスタムTableViewCellクラス。 –

答えて

1

チェックメソッド名:

public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize 

=======> sizeForItemAtIndexPath

関連する問題