Exchange Date between UITableViewController and ContentViewController with multiple pages

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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:

  1. 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.

  2. I tried Segue from tableview to the contentViewcontroller, but it does not work.

Appreciate if somebody can help me.

回答1:

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.  } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!