gpt4 book ai didi

ios - SWIFT 4 呈现 View Controller

转载 作者:行者123 更新时间:2023-11-30 11:50:05 26 4
gpt4 key购买 nike

我正在尝试使用主详细信息模板构建应用程序。在主视图 Controller 中,我添加了一个名为 Catalog 的按钮:此按钮显示一个名为 Catalogue 的选项卡栏 Controller 。

enter image description here

我不使用 Segue 来显示目录,我使用下面的代码来显示选项卡 Controller

从主表单中,我调用了 Tabbar Controller :

@IBAction func Btn_Catalogue(_ sender: Any) {
let AddCatalogueVC = self.storyboard?.instantiateViewController(withIdentifier: "CatalogueVC") as! CatalogueVC
present(AddCatalogueVC, animated: true, completion: nil)
}

从CategorieVC我使用下面的代码来显示

@IBAction func Btn_AddCategorie(_ sender: Any) {
self.Mode = "New"
let AddCategorieViewController = self.storyboard?.instantiateViewController(withIdentifier: "AddCategorieVC") as! AddCategorieVC
present(AddCategorieViewController, animated: true, completion: nil)
}

我使用下面的代码关闭 AddCategorieVC

  @IBAction func Btn_Save(_ sender: Any) 
{
if self.Txt_CategorieName.text != ""{
self.Mysave = true
self.MyCategorieName = self.Txt_CategorieName.text!
self.dismiss(animated: true, completion: nil)
}
}

我已将 SEGUE 从“保存”按钮展开到 categorieVC 中的函数

 @IBAction func FctSaveCategories(_ sender: UIStoryboardSegue) {
let sendervc = sender.source as! AddCategorieVC
if self.Mode == "New" && sendervc.Mysave == true { // Mode insert



let MyCategories = TblCategorie(context: Mycontext)
MyCategories.categorie_Name = sendervc.MyCategorieName
do {
try Mycontext.save()
} catch {
debugPrint ("there is an error \(error.localizedDescription)")
}
}
}

问题是,当我点击 categorieVC 中的保存按钮时,catalogueVC 也会消失,同时将我返回到主控件。

我几乎可以肯定问题来自 Unwind segue,但我不知道为什么。

更新:我使用以下代码激活 AddCategorieVC 中的取消按钮

  self.dismiss(animated: true, completion: nil)

当我点击它时,只有 AddCategorieVC 被忽略,然后我返回到 CatalogueVC。保存按钮和取消按钮之间的区别仅在于保存按钮上的 UNWIND segue。

当我将 UnWIND segue 添加到取消按钮(只是为了测试行为)时,它带我回到主表单而不是 CatalogueVC。

我该如何解决这个问题?

最佳答案

是的,我找到了

看起来 unwind segue 自动处理了 dismiss control

所以我需要做的就是从保存按钮中删除关闭代码,这样展开转场就会带我回到catalogueVC。

.

关于ios - SWIFT 4 呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48423313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com