Swift学习iOS UI

swift之在tableview中如何知道自己点击的是那个cel

2015-08-20  本文已影响4645人  Seizens_Swift

1 button控件

<code>

    cell.addBtn.tag = indexPath.row   //设置button的tag 为tableview对应的行
    //加入button手势事件
    cell.addBtn.addTarget(self, action: "touchUpButton:", forControlEvents: UIControlEvents.TouchUpInside)

</code>

<code>

func touchUpButton(sender: UIButton){
    
    println(sender.tag)
    
}

</code>

2 UIImage

<code>

    cell.headImage.userInteractionEnabled = true
    var signTap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "touchUpImage:")
    cell.headImage.addGestureRecognizer(signTap)
    signTap.view!.tag = indexPath.row

</code>

<code>

func touchUpImage(recognizer: UITapGestureRecognizer){
    
    println( recognizer.view!.tag)

}

</code>

3

上一篇 下一篇

猜你喜欢

热点阅读