Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 999
saner Avatar asked Jun 06 '15 15:06

saner


2 Answers

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
    }

}
like image 125
Rob Avatar answered Oct 21 '22 04:10

Rob


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



        }



}
like image 28
saner Avatar answered Oct 21 '22 04:10

saner