2017-02-17 7 views
0

Итак, у меня есть три контейнера в родительском представлении, первый из которых содержит статический табличный вид, который отлично работает. У второго ContainerView есть коллекцияView внутри него, которая прокручивает горизонтально вправо и делает выбор. & didDeselect вызывается также. Третий контейнерView также имеет в нем еще один элемент коллекции: однако он не прокручивается по горизонтали, который установлен в раскадровке, и не вызывается. Вызывается и didDeselect.Один из видов коллекции не прокручивается, внутри контейнерного вида

private let reuseIdentifier = "TimeCollectionViewCell" 

class TimeCollectionViewDataSource: NSObject, UICollectionViewDataSource { 

    private let dataSource = TimeModel() 
    private let dateFormatter = DateFormatter() 

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

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! TimeCollectionViewCell 

     // dateFormatter indicates how the string will look like 
     dateFormatter.dateFormat = "hh:mm a" 
     dateFormatter.amSymbol = "AM" 
     dateFormatter.pmSymbol = "PM" 

     // get the array of times 
     let times = dataSource.getReservationTimeIntervals() 

     cell.timeLabel.text = dateFormatter.string(from: times[indexPath.row]) 

     return cell 
    } 
} 





import UIKit 


class DateCollectionVC: UIViewController, UICollectionViewDelegate { 

    @IBOutlet weak var dateCollectionView: UICollectionView! 
    @IBOutlet weak var monthLabel: UILabel! 

    private var dateFormatter = DateFormatter() 
    private let currentDate = NSDate() 
    private var daysInMonth = Int() 
    private let dataSource = DateCollectionViewDataSource() 
    private var isSelected = false 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     dateCollectionView.dataSource = dataSource 
     dateCollectionView.delegate = self 

     monthLabel.text = getMonth() 
    } 

    // based on current Date, just extract the Month 
    func getMonth() -> String { 
     dateFormatter.dateFormat = "MMMM" 
     return dateFormatter.string(from: currentDate as Date) 
    } 

    // user taps cell & check Mark appreas or disappears 
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
     let selectedCell = collectionView.cellForItem(at: indexPath) as! DateCollectionViewCell 

     // checks to see if same cell was tapped again 
     if !isSelected { 
      selectedCell.checkMarkImageView.alpha = 0.75 
      isSelected = true 
     } else { 
      selectedCell.checkMarkImageView.alpha = 0 
     } 
    } 

    // user taps a different cell and check mark disappears 
    func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { 
     let selectedCell = collectionView.cellForItem(at: indexPath) as! DateCollectionViewCell 

     selectedCell.checkMarkImageView.alpha = 0 
    } 

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

} 
+0

полный код можно найти на GitHub https://github.com/alirezatab/WFcodingChallenge –

ответ

0

Ваш класс вид отмечен как TimeCollectionViewCell вместо UIView

enter image description here

Реализовать методы делегата, и он будет работать.

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