2015-02-10 2 views
1

У меня есть коллекцияView и заголовок для этого коллекционного представления. Я добавил UISegmentControl в свой заголовок, и теперь я пытаюсь передать значение selectedSegmentIndex в main collectionView. Поэтому я пытаюсь добавитьTarget для этого сегмента в моем UICollectionViewController, но он ничего не возвращает, вот мой кодДействие добавления 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

Смежные вопросы