【发布时间】:2017-05-26 07:27:59
【问题描述】:
我正在尝试在主从应用程序的详细视图中显示两个标签。我希望第一个标签显示“餐厅名称”,第二个标签显示“用户当前位置”。我已经成功实现了“locationManager”,并且在我的控制台中获得了正确的当前用户坐标。但是,我想在标签的文本中显示坐标。我认为以下代码的问题是第二个标签在接收到坐标之前设置。实施它的最佳方法是什么?
func configureView() {
//to display label with restaurant name
if let restaurant = self.restaurant {
if let label = self.restaurantNameLabel {
label.text = restaurant.RestaurantName
}
}
//to display label with user's Latitude and Longitude:
if let label = self.CurrentLocation {
label.text = "\(currentLocation?.longitude)"
}
}
我也有 didSet 方法:
var restaurant: Restaurant? {
didSet {
self.configureView()
}
}
var currentLocation: Coordinate? {
didSet {
self.configureView()
}
}
【问题讨论】:
标签: ios user-interface swift3 uilabel cllocationmanager