草庐IT

ios - Eureka 行在 Swift 3.0 中呈现 View Controller 和返回值

coder 2023-09-09 原文

我正在寻求帮助,以弄清楚如何让 MultivaluedSection 中的一行呈现具有第二个 Eureka 表单的 View Controller ,并将值返回给 MultivaluedSection 行。我已经能够获得一个常规的 ButtonRow 来使用 segue 推送 View Controller ,但我无法弄清楚不将值返回到 MultivaluedSection 中的行。我不确定 ButtonRow 方法是否支持返回值,所以我开始寻找其他解决方案。我发现的一个是使用自定义演示者行 ( https://github.com/xmartlabs/Eureka#custom-presenter-rows ),但我不明白如何使它起作用。

我确实找到了一件事,但同样,我不明白如何将它们放在一起:

帮助创建简单的自定义演示者行 - https://github.com/xmartlabs/Eureka/issues/716

有人可以向我指出工作示例或帮助我完成此设置吗?

最佳答案

如果您已经在推送带有 segue 的新 VC,那么您可能想要实现一个协议(protocol)并定义函数以将数据传回。

Here是一个很好的导航 Controller 教程,最后添加了一个协议(protocol)。

例如:

View one(可以是带有 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
        }
    }
}

View 二(推送的View controller)

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

关于ios - Eureka 行在 Swift 3.0 中呈现 View Controller 和返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44105004/

有关ios - Eureka 行在 Swift 3.0 中呈现 View Controller 和返回值的更多相关文章

  1. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  2. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  3. ruby - Ruby 中的隐式返回值是怎么回事? - 2

    所以我开始关注ruby​​,很多东西看起来不错,但我对隐式return语句很反感。我理解默认情况下让所有内容返回self或nil但不是语句的最后一个值。对我来说,它看起来非常脆弱(尤其是)如果你正在使用一个不打算返回某些东西的方法(尤其是一个改变状态/破坏性方法的函数!),其他人可能最终依赖于一个返回对方法的目的并不重要,并且有很大的改变机会。隐式返回有什么意义?有没有办法让事情变得更简单?总是有返回以防止隐含返回被认为是好的做法吗?我是不是太担心这个了?附言当人们想要从方法中返回特定的东西时,他们是否经常使用隐式返回,这不是让你组中的其他人更容易破坏彼此的代码吗?当然,记录一切并给出

  4. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  5. ruby - Hanami link_to 助手只呈现最后一个元素 - 2

    我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm

  6. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  7. ruby - 是否可以从 ruby​​ 脚本返回值并在 c 或 shell 脚本中读取该值? - 2

    我们如何从ruby​​脚本返回值?#!/usr/bin/envrubya="test"a我们如何在Ubuntu终端或java或c中访问'a'的值? 最佳答案 在ruby​​/python脚本中打印你的变量,然后可以通过示例从shell脚本中读取它:#!/bin/bashruby_var=$(rubymyrubyscript.rb)python_var=$(pythonmypythonscript.py)echo"$ruby_var"echo"$python_var"注意你的ruby​​/python脚本只打印这个变量(有更多复杂的方

  8. ruby - 为 IO::popen 拯救 "command not found" - 2

    当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

  9. ruby-on-rails - 我将 Rails3 与 tinymce 一起使用。如何呈现用户关闭浏览器javascript然后输入xss? - 2

    我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如

  10. ruby - IO::EAGAINWaitReadable:资源暂时不可用 - 读取会阻塞 - 2

    当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab

随机推荐