私のオブジェクトからボタンにInt64/32値を渡して、それ以上の操作を実行したいと思います。しかしbtn.tag
はInt
の値をとるので、エラーが発生し、obj.id
をInt
に変更すると、数値の最初の数を取得するだけです。私はcellBtn to btnU
からobj.id
を渡すことができますどのようにUIButton SwiftでInt64/Int32値を渡す方法
cellBtn = UIButton(frame: CGRect(x: 150, y: 30, width: 100, height: 100))
cellBtn.backgroundColor = .greenColor()
cellBtn.setTitle("Test", forState: .Normal)
//obj.id is Int64 value
cellBtn.tag = obj.id
cellBtn.addTarget(self, action: #selector(btnU), forControlEvents: .TouchUpInside)
cell?.addSubview(cellBtn)
return cell!
func btnU(sender: UIButton!) {
print("hey")
print(sender.tag)
}
のでbtnUは、私がUI要素に値を渡すことはお勧めしません、あなたはその目的のためにモデルオブジェクトを持っている必要がありobj.id
としてそれを与える新しいプロパティは 'var id:Int64'と言う。 – NSGangster
これらのタグを使用しているかどうか尋ねてもよろしいですか? – Alexander
私はあなたが欠けていると思います(:) try #selector(ClassName。btnU(_ :) –