SWIFT:不知道如何将所选值从弹出窗口恢复到调用控制器 [英] SWIFT: No idea how to get back the selected value from a popover to the calling controller

查看:88
本文介绍了SWIFT:不知道如何将所选值从弹出窗口恢复到调用控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Swift Popover的回归价值感到疯狂。我是Objectiv-C和SWIFT的新手,但我尝试专注于SWIFT。

I just going crazy on Swift Popover "return" values. I am new to Objectiv-C as well as SWIFT but I try to focus on SWIFT.

我查看了Google和StackOverflow关于如何管理iOS popovers的教程,学到了很多,但最后的和平,我无法做到。很棒,所以看看使用Swift和Xcode 6制作它是多么容易,喜欢它,但我无法弄清楚如何从我的popover中将所选值恢复到我的调用视图控制器。

I checked out tutorials around Google and StackOverflow about how to manage iOS popovers, learned a lot but the last peace I couldn’t make it. It is great so see how easy it is made using Swift and Xcode 6, love it, but I could not figure out how to get back the selected value from my popover to my calling view controller.

所以这是我的问题:
(SIDENOTE:我正在使用SWIFT并使用storyboard完成所有工作)

So here is my problem: (SIDENOTE: I am using SWIFT and do all using storyboard)

我创建了一个主人 ViewController ,带有一个选择货币的按钮。此按钮打开选择货币弹出窗口(通过CTRL将其拖动到CTV控制器链接到 CurrencyTableViewController (CTV)。

I have created a master ViewController with a button to select currencies. This button opens a "select currency" popover (linked to the CurrencyTableViewController (CTV) by CTRL-Dragging it to the CTV-Controller.

到目前为止一切顺利。问题是,我不知道如何从CTV表中取回选定的表格行(货币);-(所以我需要选择的货币(表格行)调用 ViewController

So far so good. The thing is, I have no idea how to get back the selected table row (currency) from the CTV-Table ;-( So I need the selected currency (table row) in the calling ViewController.

这是我的 ViewController (调用popover)

This is an excerpt from my ViewController (which is calling the popover)

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate 
[...]
// This button is calling the popover
@IBAction func buttonCurrency(sender: AnyObject) {
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let controller = segue.destinationViewController as? CurrencyTableViewController {
controller.popoverPresentationController?.delegate = self
return
}
}
[...]

希望有人可以帮我解决那个错过的最后一英里如何将选定的行值恢复回我的ViewController。

Hopefully somebody can help me with that missing last mile how to get back the selected row value back to my ViewController.

提前致谢

干杯

John

推荐答案

我做了一个快速的例子,希望它有所帮助:

I made quick example, hope it helps:

// This is you popover's class

@objc protocol CurrencySelectedDelegate {
    func currencySelected(currName: String)
}

class MyPopOverController: UIViewController {


    weak var delegate: CurrencySelectedDelegate?


    @IBAction func readyButtonPressed(sender: AnyObject) {

    // Do what you want

    delegate?.currencySelected("Euro/Dollar etc....")

    // close popover
    }
}

// ViewController
class ViewController: UIViewController, CurrencySelectedDelegate {

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "mySegue" { // your identifier here
            let controller = segue.destinationViewController as! MyPopOverController
            controller.delegate = self
        }
    }

}

请记住在ViewController中声明currencySelected函数。

And remember just declare that currencySelected function in your ViewController.

这篇关于SWIFT:不知道如何将所选值从弹出窗口恢复到调用控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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