多页 UITableViewController 和 ContentViewController 之间的交换日期 [英] Exchange Date between UITableViewController and ContentViewController with multiple pages

查看:25
本文介绍了多页 UITableViewController 和 ContentViewController 之间的交换日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,在该应用程序中,我需要通过单击 tableviewcontroller 中的 tableview 单元格将一组值传递给具有页面卷曲过渡的 contentview 视图控制器.

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.

每个页面都有一个 textview,它将填充从初始视图控制器传递的值,并且可以由用户编辑.

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

我尝试了以下方法:

  1. 我在我的初始视图控制器中实现了 pageviewcontroller 方法,以创建具有页面卷曲转换的 ContentViewController 实例,并且能够在页面卷曲完成时将值传递给每个页面.但是我试图找出一种方法将更新的值从我实例化对象的地方传回 tableviewcontroller.

  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.

我尝试了从 tableview 到 contentViewcontroller 的 Segue,但它不起作用.

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

感谢有人能帮助我.

推荐答案

使用委托模式.

ContentViewController 中定义一个协议:

Define a protocol within ContentViewController :

protocol UpdateModelDelegate {
    func didDismissContentViewController(controller:ContentViewController)
}

ContentViewController 中建立一个委托变量:

Establish a delegate variable within ContentViewController :

var delegate: UpdateModelDelegate?

当您关闭 ContentViewController 调用 delegate?.didDismissContentViewController(self) 时,它会将数据发送回您的 UITableViewController.

When you dismiss ContentViewController call delegate?.didDismissContentViewController(self) which will send the data back to your UITableViewController.

UITableViewController 符合这个协议.

class MyTableViewControllerSubclass: UITableviewController, UpdateModelDelegate

当呈现 ContentViewController 时,将您的 UITableViewSubclass 设置为委托.

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
}

最后,在您的 UITableviewController 子类中实现委托函数.

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

这篇关于多页 UITableViewController 和 ContentViewController 之间的交换日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆