1

I am working on a Swift application that needs to set the application scope from a tableView -- the user will select a list item which will then set an ID which controls the data loaded in other views. I am currently opening the tableView as a modal but I am not sure what is the best practice for closing the modal from within the setSelected(selected: Bool, animated: Bool) function call of a custom tableViewCell subclass (or even if dismissing the modal from this function is the best practice). I was considering passing a reference of the parent view that loaded the modal and then using dismissViewControllerAnimate but that is not working.

Edit : my original post seemed to be unclear so I will try to clearly ask my questions:

1.) I need dismiss the modal view and the only function I have come across so far is dismissViewControllerAnimate -- is this the function I should be using or are there others for others uses?

2.) If dismissViewControllerAnimate is the correct function, should I be calling it from within the setSelected function of the tableViewCell?

3.) If I should call from within setSelected, should I pass a reference of the ViewController to the tableViewCell so that it can call dismissViewControllerAnimate from setSelected?

/Edit

Any help or suggestions will be much appreciated!

5
  • 1
    please don't down-vote without explanation..
    – wilco
    Commented Jan 1, 2015 at 6:35
  • I wasn't the one who down voted but your question isn't clear. Post your code and explain where your problem occurs.
    – rakeshbs
    Commented Jan 1, 2015 at 7:54
  • this question lacks sufficient information and code, demonstrates that you did not study the basic documentation and is opinion-based. Commented Jan 1, 2015 at 14:06
  • @vikingosegundo This post is in no way opinion-based (unless you want to call best practices an "opinion", in which case, I would firmly disagree).
    – wilco
    Commented Jan 1, 2015 at 15:45
  • @vikingosegundo and you are correct about having not thoroughly studied the documentation -- I have recently picked up Swift and I am trying to work through an application as I learn it instead of learning it and then starting development so there are some tradeoffs (such as having to seek advise from those who are more experienced)
    – wilco
    Commented Jan 1, 2015 at 15:47

1 Answer 1

1

My suggestion is to handle the didSelectRowAtIndexPath method in your table view controller and call dismissViewControllerAnimated from there after noting what cell was selected.

1
  • this doesnt work for me. the controller is not closed. func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { CouponHolder.instance.setCustomer(searchResults[indexPath.row]); self.dismissViewControllerAnimated(true, completion: {}) }
    – dy_
    Commented Mar 5, 2015 at 18:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.