2017-02-17 86 views
0

所以我有三個containerViews在父視圖內,第一個包含一個靜態tableview,它工作正常。 第二個ContainerView裏面有一個collectionView,它水平滾動並且didSelect選擇& didDeselect也被調用。 第三個containerView中還有另一個collectionView;但是,它不會在故事板中設置的水平滾動,也不會調用didSelect和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

實施委託方法,它會工作。

相關問題