当我将导航 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/