2017-06-07 20 views
-1
func numberOfSections(in collectionView: UICollectionView) -> Int { 
    return 1 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int 
{ 
    return interests.count 
} 

func collectionView(_ collectionView: UICollectionView, cellForItemAt cellForItemAtindexPath: IndexPath) -> UICollectionViewCell 
{ 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell 

    cell.interest = self.interest[indexPath.item] 

    return cell 
} 
+0

として、あなたのメソッドのシグネチャを修正して 'indexPath'のPARAM – aircraft

答えて

0

変更これにスウィフトで未解決の識別子「indexPath」の使用を:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell 
{ 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell 

    cell.interest = self.interest[indexPath.item] 

    return cell 
} 

UPDATE

そして、これはあなたにも追加する必要がありますUICollectionView機能がある場合override前のキーワードfunc

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Storyboard.CellIdentifier, forIndexPath:indexPath) as! InterestCollectionViewCell 

    cell.interest = self.interest[indexPath.item] 

    return cell 
} 
2

はあなたの方法

スウィフト

func collectionView(_ collectionView: UICollectionView, 
     cellForItemAt indexPath: IndexPath) -> UICollectionViewCell 

Objective Cの

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath; 

documentation

0
extension ViewController: UICollectionViewDataSource { 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 

     return interests.count 
    } 
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.cellIdentifier, for: indexPath) as! InterestCollectionViewCell 

     cell.interest = interests[(indexPath as NSIndexPath).item] 

     return cell 
    } 
} 
+0

をすることはできていませんフォーマットしてくださいコードは適切ですか?すべての行をさらに4つのスペースでインデントする必要があるように見えます – huwr

0
//MARK:- extension of collection view 

extension CreateTapUpFirstVC : UICollectionViewDelegate, UICollectionViewDataSource , UICollectionViewDelegateFlowLayout{ 


    // MARK: - Collection View delegate & datasource 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 


      return arrCategory.count 

    } 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TappUpCell", for: indexPath as IndexPath) as! TappUpCell 

     return cell 

    } 

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){ 

    } 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { 
     let bounds = UIScreen.main.bounds 
     let height = bounds.size.height 

     if(height == 736) { 
      // return UIEdgeInsetsMake(top, left, bottom, right); 
      return UIEdgeInsetsMake(20, 40, 20, 40) 
     } else if(height == 667){ 
      return UIEdgeInsetsMake(20, 40, 20, 40) 
     } else if(height == 568) { 
      return UIEdgeInsetsMake(20, 20, 10, 20) 
     } else if(height == 480) { 
      return UIEdgeInsetsMake(20, 20, 10, 20) 
     } else { 
      return UIEdgeInsetsMake(20, 40, 20, 40) 
     } 
    } 


    func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,minimumLineSpacingForSectionAt section: Int) -> CGFloat { 

     let bounds = UIScreen.main.bounds 
     // let width = bounds.size.width 
     let height = bounds.size.height 
     if(height == 736) { 
      return 10//20 
     } else if(height == 667){ 
      return 5//15 
     } else { 
      return 5//10 
     } 
    } 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 

     return CGSize(width: 100.0, height: 100.0); 

    } 
} 
関連する問題