ios - 如何使用 Swift 中的协议(protocol)和委托(delegate)将变量从 UIViewController 传递回根导航 Controller

标签 ios swift

Xcode Image

正如您在所附图片中看到的,我有一个名为“Notifications”的根导航 Controller 和一个名为“NotificationsController”的 UIViewController。

所以我的问题是如何使用协议(protocol)和委托(delegate)将变量从NotificationsController传递回通知,因为在这种情况下没有segue,但它们之间有默认关系。

我的问题是否正确,或者是否有其他方法可以满足我的需要。

非常感谢任何帮助

最佳答案

从 View Controller 引用导航 Controller (它是可选的,因此您需要处理它):

// self is a UIViewController
self.navigationController

从导航 Controller 引用 View Controller :

// self is a UINavigationController
let index = // Index of the view controller. You may need to iterate over viewControllers to find this.
self.viewControllers[index]

关于ios - 如何使用 Swift 中的协议(protocol)和委托(delegate)将变量从 UIViewController 传递回根导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34771461/

相关文章:

ios - pod 安装后项目不工作

ios - 在 Apple 审核时,In App Purchase 无法正常工作

iOS 9 : KVO no longer working

ios - Sqlite.swift 过滤/查找

swift - 在 Swift 中添加 Storyboard

ios - 当用户滚动时如何更改 UINavigationBar barTintColor

ios - 在加载 tableView 时展开可选值时意外发现 nil

iphone - 在iphone的webview中打开下载的文件

ios - JSON数据解析异常 "objectForKey unrecognized selector"

ios - Facebook 登录不断返回 Nil - Parse/Swift