Swift:每个load viewcontroller函数运行几次
我在Swift:每个load viewcontroller函数运行几次,swift,quickblox,Swift,Quickblox,我在viewController.swift中使用以下代码 func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) { print("PLAY SESSION") } 我打开应用程序,在接收会话后,我得到一个日志播放会话 但如果我打开应用程序,进入viewControllerPage.swift,然后再次返回viewController.swift,在接收会话之后,我会
viewController.swift中使用以下代码
func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
print("PLAY SESSION")
}
我打开应用程序,在接收会话后,我得到一个日志播放会话
但如果我打开应用程序,进入viewControllerPage.swift
,然后再次返回viewController.swift
,在接收会话之后,我会得到两个日志播放会话
因此,如果我打开viewController.swift
7-8次,在接收会话后打印7-8次PLAY会话
我只想获得一次会话,即使每次打开viewController.swift
func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
print("PLAY SESSION")
}
我想要direceivenewsession
加载一次这正是viewDidload和ViewDidDisplay的用途
override func viewDidLoad() {
//insert the code you only want to run once here
}
override func viewDidAppear(_ animated: Bool){
//insert the code you want to run every time you load the VC
}
你不想使用它们有什么特别的原因吗?或者,您可以使用ViewWillAspect()而不是ViewDidAspect()这正是viewDidload和ViewDidAspect的用途
override func viewDidLoad() {
//insert the code you only want to run once here
}
override func viewDidAppear(_ animated: Bool){
//insert the code you want to run every time you load the VC
}
你不想使用它们有什么特别的原因吗?或者,您可以使用ViewWillAspect()而不是ViewDidAspect()