我想更改标签上的一些文字。这在viewDidLoad方法中按预期工作。但这在委托方法中不起作用。
代码:
class testView: UIViewController, RTCPeerConnectionDelegate, RTCDataChannelDelegate, RTCEAGLVideoViewDelegate {
@IBOutlet var statusLabel: UILabel!
override func viewDidLoad() {
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState){
if(newState == RTCIceConnectionState.connected){
DispatchQueue.main.async {
self.statusLabel.text = "Connected";
}
}
}
}
我试图在主踏板上运行“标签更新”代码。不幸的是,这没有用。为什么这不起作用?
更新
我和一位代表一起试过这个,但没有运气:
class testView: UIViewController, RTCPeerConnectionDelegate, RTCDataChannelDelegate, RTCEAGLVideoViewDelegate {
@IBOutlet var statusLabel: UILabel!
var delegate : testView!
override func viewDidLoad() {
delegate = self
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState){
if(newState == RTCIceConnectionState.connected){
DispatchQueue.main.async {
self.delegate.statusLabel.text = "Connected";
}
}
}
}