0

How to display edit screen on long press of UITableView cell and display view screen on single click of UITableView cell in swift language?

@IBAction func editMethod(sender: UILongPressGestureRecognizer) {
        if sender.state == UIGestureRecognizerState.Began {
            let cell = sender.view as! MyTableViewCell
            let editController = MyEditViewController()
            editController.sample= samples[cell.tag]
            presentViewController(editController, animated: true, completion: nil)
        }
    }

I am using this code to display my edit controller but all the field outlets in MyEditViewController are nil because of this line 'let editController = MyEditViewController()'. Here I am creating new instance. So outlets are nil now. Is there any other way?

5
  • LongPressGestureRecognizer. Single tap is handled by default through didSelectRowAtIndexPath.
    – NSNoob
    Nov 30, 2015 at 9:36
  • How can i get the selected cell number(indexpath) in the LongPressGestureRecognizer action method? Nov 30, 2015 at 10:04
  • set tag of cell to indexPath.row in cellForRowAtIndexPath delegate and by the sender of action method, get the view of sender. That will be the cell. Use its tag to know the indexPath.row.
    – NSNoob
    Nov 30, 2015 at 10:11
  • Like this: UITableViewCell *selectedCell = (UITableViewCell*)sender.view; Now use selectedCell.tag for getting the indexPath.row
    – NSNoob
    Nov 30, 2015 at 10:12
  • @NSNoob Please reply to my edited question Dec 18, 2015 at 6:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.