簡體   English   中英

查看 controller 關閉問題

[英]View controller dismiss issue

我正在設置一個具有 firebase 身份驗證的新應用程序

當您是注冊用戶時,您可以創建和發布添加(項目)以便其他人可以看到它。 但是,如果您沒有登錄用戶,它會顯示一個登錄彈出窗口! 有一個 DISMISS 按鈕!

例如,我嘗試創建一個 if 語句

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if segue.identifier == "itemToAddItemSeg" {
            let vc = segue.destination as! AddItemViewController
            vc.category = category!
            }
        }

    private func showItemView(_ item: Item) {

        let itemVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "itemView") as! ItemViewController
        itemVC.item = item

        self.navigationController?.pushViewController(itemVC, animated: true)  
    }

    //Mark: Load items
    private func loadItems() {
        downloadItemsFromFirebase(category!.id) { (allItems) in
            self.itemArray = allItems
            self.tableView.reloadData()   
        }
    }

    private func showLoginView() {
        let loginView = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "loginView") 
        self.present(loginView, animated: true, completion: nil)
    }  
}

需要實現哪些代碼? - 所以如果我的showlogin 彈出來! 有人會按下關閉按鈕它不會繼續到AddItemViewCotroller

此外,它將留在itemViewController的同一頁面上

Swift 5

dismiss(animated: true, completion: nil)

關閉視圖 controller 模態呈現的視圖 controller。

根據您提供的代碼,我無法告訴您如何調用您的駁回 function,但是實現駁回方法的示例:

func dismissButtonTapped() {
   dismiss(animated: true, completion: nil) 
}

同樣,不確定您如何稱呼您的 function,但上面的示例應該足以引導您朝着正確的方向前進。

這將關閉 showLoginView 並將用戶保留在 itemViewController 上。

由於您在道德上展示了您的 loginView,這應該可以解決問題。

查看有關dismiss(animated:, completion:)方法的文檔以獲取更多詳細信息。

正如我之前所說,問題在於轉換,如果我實現了錯誤的代碼,我真的很抱歉。 如果 Muser.curentUser() != nil ,問題出在我實現代碼的地方

有一個更好的地方,當有人按下完成按鈕時,他們會問他們是否是注冊用戶? 在其他地方添加一個顯示登錄視圖彈出窗口解決了這個問題對不起伙計們!! 謝謝你,你是最好的,非常好的人,因為你試圖幫助我! 太感謝了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM