除非我触摸第二个选项卡并返回主选项卡,否则无法再次选择集合视图单元格

时间:2016-02-22 04:39:00

标签: ios swift tabs cell collectionview

我有一个标签式应用程序。

我有一个集合视图。当用户点击集合视图单元格时,将显示一个新视图。当用户通过触摸手势关闭该视图时,整个视图将从超级视图中删除,因此您只能看到集合视图。

我现在可以向上向上滚动集合视图,但是即使我在视图关闭时取消选择所有单元格,也无法选择新单元格。

有趣的是,当我点击第二个标签然后回到此标签时,我现在可以再次选择一个单元格。

有人可以解释发生了什么吗?

这是我的单独视图文件中的代码,它直接位于类init方法中:

  //set cancel icon properties
    self.escapeIcon.image = UIImage(named: "Ninja")
    self.escapeIcon.image?.roundImage()
    self.escapeIcon.userInteractionEnabled = true
    let closeSelector: Selector = "close:"
    let tapOnIcon = UITapGestureRecognizer(target: self, action: closeSelector)
    tapOnIcon.delegate = self
    tapOnIcon.numberOfTapsRequired = 1
    escapeIcon.userInteractionEnabled = true
    escapeIcon.addGestureRecognizer(tapOnIcon)

    //add to card header
    cardHeader.addSubview(escapeIcon)
    bringSubviewToFront(escapeIcon)

然后我在同一个视图文件中创建名为“Close:”的选择器函数,如下所示:

lazy var collectView:UICollectionView = UICollectionView()
var path:NSIndexPath = NSIndexPath()
var celly:CollectionViewCell = CollectionViewCell()

func close(sender:UITapGestureRecognizer) {
    print("execution")
    //unblur animation
    self.superview?.darkUnBlurBackGround(self.superview!, frame: (self.superview?.bounds)!, duration: 1.0)
    //the collectView is a reference pointer to the collectionview in the 
    //view controller file so here I enable scrolling again
    self.collectView.scrollEnabled = true
    //I then remove this "card view" from the superview so that only the collectionview is now visible
    self.removeFromSuperview()
    // I deselect all items in the collectionview and reload everything
    self.collectView.deselectAllItems(true)
    self.collectView.reloadInputViews()
    self.collectView.reloadData()
    self.collectView.allowsMultipleSelection = true
}

在我的视图控制器文件中,当用户选择一个单元格时,我会执行以下操作:

//Create actions for when a user selects a collection view cell
var currentlySelectedEntrepreneur: Entrepreneur = Entrepreneur()

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    //pause scrolling on collection view while cell is selected
    collectionView.scrollEnabled = false

    //animation to blur out background
    collectionView.darkBlurBackGround(collectionView, frame: collectionView.bounds, duration: 0.5)

    //update global entrepreneur variable with entrepreneur instance
    currentlySelectedEntrepreneur = entrepreneurData[indexPath.item]

    //decode image url by name
    let imgURL = imageName[currentlySelectedEntrepreneur.name]

    //Update card view origin based on last content offset value
    cardView.updateCardViewFrameOrigin(0, y: lastContentOffset)
    //add image
    cardView.image.image = imageData[imgURL!]
    //add data with animation
    cardView.cardTitle.setTextWithTypeAnimation(currentlySelectedEntrepreneur.name)
    //add age, company and networth values
    cardView.cardLabelAge.labelDetails.text =  "\(currentlySelectedEntrepreneur.age)"
    cardView.cardLabelCompany.labelDetails.text = currentlySelectedEntrepreneur.company
    cardView.cardLabelNetworth.labelDetails.text = "\(currentlySelectedEntrepreneur.netWorth) \(currentlySelectedEntrepreneur.netWorthDenomination)"

    //reload table data and reset frame
    cardView.myTableView.reloadData()
   // cardView.myTableView.tableFooterView = UIView(frame: CGRect.zero)
    cardView.myTableView.setContentOffset(CGPointMake(0, -cardView.myTableView.contentInset.top), animated: true)


    //create a reference to the collectionview from the card view
    cardView.collectView = self.collectionView
    cardView.celly = collectionView.cellForItemAtIndexPath(indexPath) as! CollectionViewCell

    //self.collectionView.deselectAllItems(true)

    collectionView.addSubview(cardView)

}

由于

0 个答案:

没有答案