-2

I've a tableView with custom cells.

Cell has programmatically created button (added via addSubview) in customCell.swift-file (and here we're working)

How can I make an action for this button which will push another viewController via navigationViewcontroller?

(I know how to create action but do not how to push VC from this function)

SwiftStudier
  • 2,272
  • 5
  • 21
  • 43

1 Answers1

-1

Inside the definition of your button which may look like the below, you define a target action.

        let editButton = UIButton()
        editButton.frame = CGRectMake(0, 0, 60, 35)
        editButton.setTitle("Edit ", forState: .Normal)
        editButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
        editButton.addTarget(self, action: Selector("editButtonPressed"), forControlEvents: .TouchUpInside)

then in the editButtonPressed (for this example), do this:

func editButtonPressed()
{
 self.performSegueWithIdentifier("nameOfSegue", sender: self)
}
ksa_coder
  • 1,393
  • 3
  • 15
  • 38