gpt4 book ai didi

ios - 如何在 Swift 中呈现 UI View 并保留 Tab 栏

转载 作者:行者123 更新时间:2023-11-28 13:52:10 25 4
gpt4 key购买 nike

我无法在 Swift 中成功呈现 UI View 并保留 Tab 栏。它确实成功呈现,但没有标签栏。显示 UIView 似乎会删除选项卡栏。这是我的代码。

navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(goMessages))

这是我用的。

class MessagesController: UITableViewController {
let cellId = "cellId"

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(goMessages))

let image = UIImage(named: "new_message_icon")
navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(handleNewMessage))

checkIfUserIsLoggedIn()

tableView.register(UserCell.self, forCellReuseIdentifier: cellId)

// observeMessages()
}

@objc func goMessages() {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Messages = storyBoard.instantiateViewController(withIdentifier: "Messages") as! MainMSGController
self.present(Messages, animated:true, completion:nil)

最佳答案

您必须将 View Controller 推送到您的 navigationViewController 中。

但如果您没有,则应将 MessagesController 嵌入到 UINavigationViewController 中。(在您的 Main.storyboard 中,选择 MessagesController,然后从菜单 Editor -> Embed in -> Navigation Controller 中选择)

然后:

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Messages = storyBoard.instantiateViewController(withIdentifier: "Messages") as! MainMSGController
navigationController?.pushViewController(viewController: Messages, animated: true)

要关闭它,您可以:

navigationController?.popViewController(animated: true)

关于ios - 如何在 Swift 中呈现 UI View 并保留 Tab 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54421961/

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