2015-02-10 38 views
1

我有一个collectionView和一个集合视图的标题。我已经在我的头文件中添加了UISegmentControl,现在我试图将selectedSegmentIndex值传递给主collectionView,因此我试图在UICollectionViewController中为该段添加Target,但它不返回任何内容,这里是我的代码UICollectionView在标题中添加动作(Swift)

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) 
    } 

回答

1

正确的控制活动将是.ValueChanged

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

喔该死正确 – Ankit 2015-02-10 11:10:09

相关问题