gpt4 book ai didi

ios - 无法更改右侧导航按钮标题

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

我在 .viewWillAppear 中设置了一个右侧导航按钮,如下所示类 ChatMessageViewController..

let button2 = UIBarButtonItem(image: nil, style: .plain, target: self, action: #selector(blockPressed(sender:)))
button2.title = "Block"
self.navigationItem.rightBarButtonItem = button2

现在,点击 blockPressed 另一个共享函数就会像这样被调用......

@objc fileprivate func blockPressed(sender: UIButton) {
XMPPConfig.shared.blockUser(userJID: theUserJID!) //XMPPConfig is another class having some common functions and delegate methods.

}

(这个函数基本上会阻止某个用户,就像阻止 Whatsapp 用户一样。一旦发生阻止,就会调用某些委托(delegate)方法。在我更改 Block 按钮之后,这样的委托(delegate)方法如下所示。 .)

func xmppBlocking(_ sender: XMPPBlocking!, didBlockJID xmppJID: XMPPJID!) {
print("successfully blocked!")

ChatMessageViewController.shared.setupUnBlock()

}

这样做也可以正确调用 ChatMessageViewController 中的 setupUnBlock() 函数,如下所示...

func setupUnBlock() {

if XMPPConfig.shared.sectionGroupsFlag == false {
let button2 = UIBarButtonItem(image: nil, style: .plain, target: self, action: #selector(unblockPressed(sender:)))
button2.title = "Unblock"
self.navigationItem.rightBarButtonItem = button2
}
}

但是按钮标题仍然保持不变......即它仍然是“阻止”..这可能是什么原因......?

最佳答案

您应该使用另一个初始化程序来初始化您的UINavigationBarButton:

let right = UIBarButtonItem(title: "Some title", style: .plain, target: self, action: #selector(rightNavBarButtonPressed))

您正在使用 UIBarButtonItem(image:...

关于ios - 无法更改右侧导航按钮标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52817149/

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