【问题标题】:UICollectionView adding action in Header (Swift)UICollectionView 在 Header (Swift) 中添加操作
【发布时间】:2015-04-10 09:05:35
【问题描述】:

我有一个 collectionView 和该 collection view 的标题。我在标题中添加了一个 UISegmentControl,现在我试图将 selectedSegmentIndex 值传递给主 collectionView,所以我试图在我的 UICollectionViewController 中为该段添加目标,但它没有返回任何内容,这是我的代码

 override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

        let headerView = self.collectionView?.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "header", forIndexPath: indexPath) as collectionHeaderView
        headerView.controlSegment.userInteractionEnabled = true
        headerView.controlSegment.addTarget(self, action: "segmentAction:", forControlEvents: UIControlEvents.TouchUpInside)
        return headerView
    }

    func segmentAction(sender: UISegmentedControl) {
        println(sender.selectedSegmentIndex)
    }

【问题讨论】:

    标签: swift uicollectionview uisegmentedcontrol


    【解决方案1】:

    正确的控制事件应该是.ValueChanged:

    headerView.controlSegment.addTarget(self, 
            action: Selector("segmentAction:"), forControlEvents: .ValueChanged)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多