You can do this inside the cellForRowAtIndexPath viewcontroller function:
var btn = UIButton(frame: CGRectMake(100, 100, 100, 20));
btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal);
btn.setTitle("My Button", forState:UIControlState.Normal);
btn.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside);
cell.contentView.addSubview(btn)
Add another function to the same class that will receive the event with the button pressed
func buttonTapped(sender: UIButton!)
{
println("Button Tapped")
}
source
share