Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 手势识别器不';t在其他UICollectionViewCell内部处理UICollectionView_Ios_Swift_Uicollectionview - Fatal编程技术网

Ios 手势识别器不';t在其他UICollectionViewCell内部处理UICollectionView

Ios 手势识别器不';t在其他UICollectionViewCell内部处理UICollectionView,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我创建了一个UICollectionView作为主UICollectionView,每个collectionViewCell都有另一个UICollectionView“B”作为其子视图 然后我在“B”中加上一个轻拍手势。但是“B”不能触发这个手势。 以下是我的主要代码: 主UICollectionView import Foundation import UIKit class mainViewController :UIViewController,UICollectionViewDataS

我创建了一个UICollectionView作为主UICollectionView,每个collectionViewCell都有另一个UICollectionView“B”作为其子视图 然后我在“B”中加上一个轻拍手势。但是“B”不能触发这个手势。 以下是我的主要代码:

主UICollectionView

import Foundation
import UIKit

class mainViewController :UIViewController,UICollectionViewDataSource,UICollectionViewDelegate {

    @IBOutlet weak var mainCollectionView: UICollectionView!

    override func viewDidLoad() {
        self.mainCollectionView.registerNib(UINib(nibName: "OuterCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "OuterCollectionViewCell")
        self.mainCollectionView.delegate = self
        self.mainCollectionView.dataSource = self
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return 1
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("OuterCollectionViewCell", forIndexPath: indexPath) as! OuterCollectionViewCell
        return cell
    }

}
UICollectionView B:

class OuterCollectionViewCell: UICollectionViewCell,UICollectionViewDataSource, UICollectionViewDelegate {

    @IBOutlet weak var InnerCollectionView: UICollectionView!

    override func awakeFromNib() {
        super.awakeFromNib()
        InnerCollectionView.registerNib(UINib(nibName: "InnerCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CellInner")
    }

    func handleTapGesture(sender: UITapGestureRecognizer) {
        print("tapguesture")
    }

    override func didMoveToWindow(){
        let tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
        InnerCollectionView.backgroundColor = UIColor.redColor()
        InnerCollectionView.addGestureRecognizer(tapGesture)
        InnerCollectionView.delegate = self
        InnerCollectionView.dataSource = self

    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CellInner", forIndexPath: indexPath) as! InnerCollectionViewCell
        return cell
    }
}
这个问题困扰了我一整天。有没有人对如何解决这个问题有任何想法

我已将项目上载到github:

更新

今天,我通过可编程的代码初始化innerCollectionView,而不是通过NIB初始化。它是有效的

let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
let InnerCollectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: 800, height: 600), collectionViewLayout: flowLayout)
我不知道笔尖对UIcollectionview做了什么
我确实在界面生成器中将userInteractive设置为true

是您的
InnerCollectionView。UserInteractiveEnable
设置为
true
?是设置为true无影响