我已创建5个按钮动态斯威夫特这样的:如何获取UIButton ID?
for theIndex in 0..<5 {
let aButton = UIButton()
aButton.frame = CGRectMake(self.view.bounds.width/2 - 120, self.view.bounds.height/2 - 150, 240, 300)
aButton.setTitle("Button \(theIndex)", forState: .Normal)
aButton.addTarget(self, action: "btnClicked:", forControlEvents:.TouchUpInside)
self.view.addSubview(aButton)
}
但我怎么能得到BUTTON_ID为每一个?
func btnClicked(sender: AnyObject?) {
let vc = storyboard!.instantiateViewControllerWithIdentifier("vc_name") as! DetailVC
vc.selectedId = **WANT_TO_PASS_BUTTON_ID_HERE**
self.presentViewController(vc, animated:true, completion:nil)
}
考虑设置按钮的标签*或*将5个自定义按钮的数组存储在您的班级中。 – luk2302