0

我正在尝试将导航栏和后退按钮添加到 MessageKit 中 MessageViewController 的顶部。但是,后退按钮的 UIBarButtonItem 无法显示。下面是我的代码

func setUpNavBar() {
        let navBar = UINavigationBar(frame: CGRect(x: 0, y: 45, width: UIScreen.main.bounds.width, height: 44))
        self.view.addSubview(navBar)
        navBar.items?.append(UINavigationItem(title: "XXXX"))
        let backButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(onCancel))
        self.navigationItem.leftBarButtonItem = backButton
    }

上面的函数在viewDidLoad(). 我认为我的代码是正确的我似乎无法找到按钮不显示的原因。谢谢。

4

1 回答 1

1

看来我需要更换

self.navigationItem.leftBarButtonItem = backButton

navBar.topItem?.leftBarButtonItem = backButton
于 2018-12-07T18:08:18.933 回答