2017-11-22 13 views
-2

Delegate and datasource are also set UICollectionViewControllerをサブクラス化しましたが、UICollectionViewのすべてのデータソースメソッドが呼び出されていますが、UICollectionViewDelegateメソッドが呼び出されません。理由は何か。 ?以下は、UICollectionViewControllerサブクラスの実装です。UICollectionViewDelegateメソッドがUICollectionViewControllerサブクラスで呼び出されていない

class CollectionCollectionViewController: UICollectionViewController { 

    let carImages = ["mini_small","rover_small","smart_small","highlander_small","venza_small","volvo_small","vw_small","nissan_small","honda_small","jeep_small"] 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

/* 
// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} 
*/ 

// MARK: UICollectionViewDataSource 

override func numberOfSections(in collectionView: UICollectionView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 


override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of items 
    return carImages.count 
} 

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as! MyCollectionViewCell 
    let path = Bundle.main.url(forResource: carImages[indexPath.row], withExtension: "jpg") 
    let data = try! Data(contentsOf: path!) 
    cell.imgView.image = UIImage(data: data) 
    return cell 
} 

// MARK: UICollectionViewDelegate 


// Uncomment this method to specify if the specified item should be highlighted during tracking 
override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { 
    return true 
} 

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    let path = Bundle.main.url(forResource: carImages[indexPath.row], withExtension: "jpg") 
    let data = try! Data(contentsOf: path!) 
    let image = UIImage(data: data) 
    return image!.size 
} 

答えて

2

このヘルプ

この

self.collectionView.delegate = self 

希望を試します

関連する問題