saner
saner

Reputation: 821

Create Action For Static Cell Clicked in UITableView

How can I make a static table view to create an action when one of the cells is clicked in Swift?

I have created a static table like a general menu of the app, I can directly create a push segue when one of the cells are clicked. But at the same time when I click to one of the seques, I want the below function to be run. By draging a cell to the UITableView in storyboard the create action option is not appearing.

    var goToProfiles = PFObject(className: "goToProfile")    
    goToProfiles["user"] = PFUser.currentUser()!.username
    goToProfiles["goToUser"] = usernameLbl.text
    goToProfiles.save()

Upvotes: 6

Views: 11534

Answers (3)

JP Lno
JP Lno

Reputation: 91

For swift 3 compatibility:

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    //Your action here
 }

Upvotes: 7

Rob
Rob

Reputation: 7084

If you use sections you will also need to query them.

override func tableView(tableView: UITableView, 
    didSelectRowAtIndexPath indexPath: NSIndexPath) {

    print(indexPath.section)
    print(indexPath.row)

    if indexPath.section == 1 && indexPath.row == 1 {
        // do something
    }

}

Upvotes: 14

saner
saner

Reputation: 821

I found the solution with the code below:

override func tableView(tableView: UITableView,
    didSelectRowAtIndexPath indexPath: NSIndexPath) {


        if indexPath.row == 1 {

      //here you can enter the action you want to start when cell 1 is clicked



        }



}

Upvotes: 10

Related Questions