UICollectionView在标题中添加动作(Swift)
问题描述:
我有一个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)
}
答
正确的控制活动将是.ValueChanged
:
headerView.controlSegment.addTarget(self,
action: Selector("segmentAction:"), forControlEvents: .ValueChanged)
喔该死正确 – Ankit 2015-02-10 11:10:09