【发布时间】:2020-06-24 10:39:57
【问题描述】:
我正在获取cellForRowAt indexPath 中的所有值,这里根据它的索引我需要值.. 我正在获取行索引,但我正在获取该行值:
我在单元格中有按钮.. 所以如果我点击按钮然后我需要那个单元格的纬度和经度
这里我需要cellForRowAt 纬度,openMapForPlace() 中的经度,但为什么不来?*
代码如下:
var latitude: Double!
var longitude: Double!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userModel?.userAddresses.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: AddresCell = tableView.dequeueReusableCell(withIdentifier: "AddresCell", for: indexPath) as! AddresCell
let addr = userModel?.userAddresses![indexPath.row]
cell.delegate = self
cell.name.text = addr?.type
cell.typeAddLabel.text = addr?.addressName
let street = addr?.streetName
let colony = addr?.colony
let city = addr?.city
let pincode = addr?.pincode
let locality: String = addr?.buildingName ?? ""
let dorNum: String = addr?.houseNo ?? ""
let coord = addr?.location
latitude = coord?.latitude
longitude = coord?.longitude
cell.address.text = street! + "," + colony! + "," + city! + "," + pincode! + "," + locality + "," + dorNum
print("cellForRowAt indexPath \(indexPath.row) \(latitude), \(longitude)")
addressStr = street! + "," + colony! + "," + city! + "," + pincode! + "," + locality + "," + dorNum
cell.directions.tag = indexPath.row
return cell
}
func btnDirectTapped(cell: AddresCell) {
if let indexPath = self.addressTableview.indexPath(for: cell)
{
openMapForPlace()
print("selecte coordinates222 \(latitude!), \(longitude!)")
print("tableview row indexpath dir btn\(indexPath.row)")
print(indexPath.row)
}
}
func openMapForPlace() {
print("selecte coordinates1111 \(latitude!), \(longitude!)")
let regionDistance:CLLocationDistance = 10000
let coordinates = CLLocationCoordinate2DMake(12.9716, 77.5946)
let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = "Place Name"
mapItem.openInMaps(launchOptions: options)
}
【问题讨论】:
标签: ios swift xcode uitableview variables