我有下面的代码有问题:斯威夫特3 - UITextView的不更新
@IBOutlet var infoBox: UITextView!
LibPerso.startGPSLocationService(completion: {(response:Response, location:CLLocation?) -> Void in
if(response.hasError()){
//...
}
if let currentLocation = location, location != nil, location?.coordinate.latitude != 0, location?.coordinate.longitude != 0{
DispatchQueue.main.async {
print(self.infoBox.text) //#1
self.infoBox.text = "Lat : \(currentLocation.coordinate.latitude) \r\nLng: \(currentLocation.coordinate.longitude)"
print(self.infoBox.text) //#2
}
}
})
当我打开这个观点,并呼吁在我的图书馆方法startGPSLocationService
(方法,它是一个服务来获取GPS位置),每次我有回报时,我都成功更新了textView。
问题是,当我更改视图(回到上一个视图)并重新打开此视图时,将调用所有代码,但屏幕上未更新infoBox
。
我有打印两个打印语句如下:
#1:纬度:48.7922072828896 LNG:10.16013687006524
#2:纬度:48.7922120134739 LNG:10.16015784907253
所以收件箱场正确更新,但在我的屏幕上,没有任何反应。
我已经试过做self.infoBox.setNeedsLayout()
或setNeedsDisplay()
,但这也不会改变任何东西。
我认为当我回去重新打开这个视图时,对infoBox
的引用会丢失。
是从另一个屏幕返回时调用的完成块。完成块不是方法。 ? – Priyal
是的,显示两个“打印”,所以完成块被称为 – Banana
infoBox的检查框。 – KKRocks