在 Swift 3.0 中呈现视图控制器和 return 值的 Eureka 行
Eureka row to present view controller and return value in Swift 3.0
我正在寻求帮助,以弄清楚如何让 MultivaluedSection 中的一行呈现具有第二个 Eureka 表单的视图控制器,并且 return 返回 MultivaluedSection 行的值。我已经能够获得一个常规的 ButtonRow 来使用 segue 推送视图控制器,但我无法弄清楚不将值返回到 MultivaluedSection 中的行。我不确定 ButtonRow 方法是否支持 returning 值,所以我开始寻找其他解决方案。我发现的一个方法是使用自定义演示者行 (https://github.com/xmartlabs/Eureka#custom-presenter-rows),但我不明白如何实现它。
这是我找到的一件事,但同样,我不明白如何将它们放在一起:
帮助创建简单的自定义演示者行
- https://github.com/xmartlabs/Eureka/issues/716
有人可以向我指出工作示例或帮助我完成此设置吗?
如果您已经在使用 segue 推送新的 VC,那么您可能想要实现一个协议并定义函数以传回数据。
Here 是一个很好的导航控制器教程,最后添加了一个协议。
例如:
视图一(可以是带有 ButtonRow 的 Form View Controller)
class FormVC: FormViewController , FooViewControllerDelegate{
var text : String!
override func viewDidLoad() {
super.viewDidLoad()
}
/// Delegate protocol callback implementation
func myVCDidFinish(controller: FooViewController, text: String) {
// Receive the data as a delegate
self.text = text
// In this case we also want to finish the view
controller.navigationController?.popViewController(animated: true)
}
/// This represents the prepare for segue mentioned as implemented in the question
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Act upon the segue we want from this VC
// The string is defined in the storyboard, so it must be exactly the same
if segue.identifier == "mySegue"{
// Creating the second VC instance
let vc = segue.destination as! FooViewController
// Since this class is now a delegate, setup the delegate
vc.delegate = self
}
}
}
视图二(推送的视图控制器)
protocol FooViewControllerDelegate {
func myVCDidFinish(controller: FooViewController, text: String)
}
class FooViewController: UIViewController {
/// Data
var text : String!
/// Set up an optional delegate
var delegate:FooViewControllerDelegate? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Init label
self.text = "Pushed view data to pass back
}
}
我正在寻求帮助,以弄清楚如何让 MultivaluedSection 中的一行呈现具有第二个 Eureka 表单的视图控制器,并且 return 返回 MultivaluedSection 行的值。我已经能够获得一个常规的 ButtonRow 来使用 segue 推送视图控制器,但我无法弄清楚不将值返回到 MultivaluedSection 中的行。我不确定 ButtonRow 方法是否支持 returning 值,所以我开始寻找其他解决方案。我发现的一个方法是使用自定义演示者行 (https://github.com/xmartlabs/Eureka#custom-presenter-rows),但我不明白如何实现它。
这是我找到的一件事,但同样,我不明白如何将它们放在一起:
帮助创建简单的自定义演示者行 - https://github.com/xmartlabs/Eureka/issues/716
有人可以向我指出工作示例或帮助我完成此设置吗?
如果您已经在使用 segue 推送新的 VC,那么您可能想要实现一个协议并定义函数以传回数据。
Here 是一个很好的导航控制器教程,最后添加了一个协议。
例如:
视图一(可以是带有 ButtonRow 的 Form View Controller)
class FormVC: FormViewController , FooViewControllerDelegate{
var text : String!
override func viewDidLoad() {
super.viewDidLoad()
}
/// Delegate protocol callback implementation
func myVCDidFinish(controller: FooViewController, text: String) {
// Receive the data as a delegate
self.text = text
// In this case we also want to finish the view
controller.navigationController?.popViewController(animated: true)
}
/// This represents the prepare for segue mentioned as implemented in the question
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Act upon the segue we want from this VC
// The string is defined in the storyboard, so it must be exactly the same
if segue.identifier == "mySegue"{
// Creating the second VC instance
let vc = segue.destination as! FooViewController
// Since this class is now a delegate, setup the delegate
vc.delegate = self
}
}
}
视图二(推送的视图控制器)
protocol FooViewControllerDelegate {
func myVCDidFinish(controller: FooViewController, text: String)
}
class FooViewController: UIViewController {
/// Data
var text : String!
/// Set up an optional delegate
var delegate:FooViewControllerDelegate? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Init label
self.text = "Pushed view data to pass back
}
}