2016-02-07 3 views
0

У меня есть UITapGestureRecognizer на А UILabel в UITableViewCell, добавить цель указанной UITapGestureRecognizer как контроллер вида, как и в:UITableViewCell: UITapGestureRecognizer непризнанная селектор отправляется ошибка экземпляра

class Cell: UITableViewCell { 

    @IBOutlet weak var label: UILabel! 
    override func awakeFromNib() { 
     super.awakeFromNib() 
     let tap1 = UITapGestureRecognizer(target: ViewController(), action: "selectLabel:") 
     label.addGestureRecognizer(tap) 
    } 
} 

class ViewController: UIViewController,UITableViewDataSource, UITableViewDelegate{ 

    fun selectLabel(gesture: UITapGestureRecognizer){ 
     //animate some view in custom cell 
    } 
} 

Однако, Я получаю сообщение об ошибке «UITapGestureRecognizer unrecognized selector sent to instance».

+1

Можете ли вы сказать нам, что "ViewController()" означает? :) – Eendje

ответ

0

Набор жест cellForRowAtIndexPath.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as! Cell 
    let tap1 = UITapGestureRecognizer(target: self, action: "selectLabel:") 
    cell.label.addGestureRecognizer(tap1) 
    return cell 
    } 
+0

Делая это создаст сильный опорный цикл, если вы удалите этот жест, например, 'prepareForReuse' с:' gestureRecognizers .forEach (removeGestureRecognizer) '?. – Eendje

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