swift - 连接到主视图显示时,Xcode 导航栏项目消失

标签 swift xcode

当我将导航 Controller 嵌入到 MainView 并创建新的 ViewController 时。

所以我有两个 ViewController(A,B)。我在 B 中插入新的导航栏,并在 B 新导航栏中插入按钮。

我将新按钮拖到 B swiftFile 并重命名“保存按钮”

@IBAction Save(_ sender : Any){

}

我还设置了 B 新按钮 control+drag -> A Controller -> Show

之后,B 保存按钮消失,但效果很好,但保存方法不起作用。

我想当我在保存方法过程中按下保存按钮时

UserDefault.standard.set(information)

并获取有关 Controller 的信息。

我几乎完成了这个过程,但“保存”按钮不起作用。

我应该做什么?

最佳答案

请按照以下步骤操作:

第一步:

A类之前添加navigationController。添加显示按钮

第二步:显示按钮操作中写入

let yourViewController = self.storyboard?.instantiateViewController(withIdentifier: "yourViewControllerId") as? yourViewController
self.navigationController?.pushViewController(yourViewController!, animated: true)

第三步:B 类 中添加“保存”按钮。在保存按钮操作中请写:

UserDefaults.standard.set(information, forKey: "information")
UserDefaults.standard.synchronize()
self.navigationController?.popViewController(animated: true)

第四步:

然后您将在A类中的ViewWillAppear方法中获取值

也许对你有帮助。谢谢。

关于swift - 连接到主视图显示时,Xcode 导航栏项目消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54277505/

相关文章:

ios - 如何使用 segues 在 View Controller 之间传输数据

ios - 将 xcode 更新到版本 7 并将代码迁移到 swift 2。我无法运行链接错误

iphone - iPhone OS > 用户界面的 Window XIB 和 View XIB 模板之间的区别在哪里?

ios - 如何将新数据附加到现有的 JSON 数组 (swiftyJSON)

ios - setTranslatesAutoresizingMaskIntoConstraints : Cannot call value of non-function type Bool

ios - ios中的联系人选择器以获取电话号码

ios - 未找到框架 MicrosoftBandKit_iOS

objective-c - 基于 NSDocument 的应用程序窗口位置

swift - 填充 CirleProgressView 并将结果保存到 UserDefaults

ios - 在具有委托(delegate)的 View Controller 之间传递多个值