I am working on an application where I need to pass an array of values from a click of tableview cell in my tableviewcontroller which is the initial view controller to a contentview view controller with page curl transition.
Each of the page will have a textview which will be populated with value passed from the initial view controller and can be edited by the user.
My issue is, I am not able to update the array with the new value and pass it back to the initial view controller
I tried the following:
I implemented pageviewcontroller methods in my initialview controller to create instances of the ContentViewController with page curl transition and was able to pass values to each of the pages when the page curl was done. But I am trying to figure out a way to pass back the updated value to the tableviewcontroller from where I instantiated the object.
I tried Segue from tableview to the contentViewcontroller, but it does not work.
Appreciate if somebody can help me.
Use the delegate pattern.
Define a protocol within ContentViewController
:
protocol UpdateModelDelegate { func didDismissContentViewController(controller:ContentViewController) }
Establish a delegate variable within ContentViewController
:
var delegate: UpdateModelDelegate?
When you dismiss ContentViewController
call delegate?.didDismissContentViewController(self)
which will send the data back to your UITableViewController
.
Have the UITableViewController
conform to this protocol.
class MyTableViewControllerSubclass: UITableviewController, UpdateModelDelegate
When presenting the ContentViewController
set your UITableViewSubclass
as the delegate.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { var contentViewController: ContentViewController() //After you pass the necessary data to contentViewController... contentViewController.delegate? = self }
finally, implement the delegate function within your UITableviewController
subclass.
func didDismissContentViewController(controller:ContentViewController) { //You're passed in the contentViewController here, use relevant data to update your model. }