我要调用函数
func setupChatLogForUser(user: ChatPartner){
let layout = UICollectionViewFlowLayout()
let chatLog = ChatHistory(collectionViewLayout: layout)
chatLog.user = user
navigationController?.pushViewController(chatLog, animated: true)
}
在我的 TabBarController 的不同选项卡中。
作为第一步,我更改了选项卡,但之后不知道如何调用特定用户的函数,因为我也使用 navigationController 来推送 View Controller ...
感谢您的帮助!
编辑:
var chatsViewController:HomeScreen?
func chat(){
print("Chat clicked")
guard let chatFriends = self.friend else {return}
print(chatFriends)
self.tabBarController?.selectedIndex = 0
self.chatsViewController?.setupChatLogForUser(user: chatFriends)
}
最佳答案
您没有在此处初始化 chatsViewController
的 HomeScreen
实例,根据您发布的代码看起来它是 nil。您可以像这样调用方法而无需全局创建实例
func chat(){
print("Chat clicked")
guard let chatFriends = self.friend else {return}
print(chatFriends)
self.tabBarController?.selectedIndex = 0
HomeScreen().setupChatLogForUser(user: chatFriends)
}
希望对您有所帮助。
关于ios - Swift:从不同的选项卡中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45895201/