我有两个屏幕,第一个“ViewController”有tableview,第二个“MapViewController”包含MKMapView,当我从第一个导航到第二个第二个看起来像黑屏第二个屏幕应该出现苹果地图可以一个帮帮我?
import UIKit
import MapKit
struct Category {
let place : String
let coordinates : [Double]
}
class ViewController: UIViewController {
private let tableview : UITableView={
let table = UITableView()
table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
return table
}()
private let data : [Category]=[
Category(place: "Misr bank ", coordinates: [30.576352,31.503955])
]
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableview)
tableview.delegate=self
tableview.dataSource=self
}
override func viewDidLayoutSubviews() {
tableview.frame=view.bounds
}
}
extension ViewController:UITableViewDelegate{
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let category = data[indexPath.row]
let mapview = MapViewController(coor: category.coordinates)
self.navigationController?.pushViewController(mapview, animated: true)
}
}
地图视图控制器
import UIKit
import MapKit
class MapViewController: UIViewController {
@IBOutlet weak var map: MKMapView!
private let coor : [Double]
init(coor:[Double]){
self.coor=coor
super.init(nibName: nil, bundle: nil)
let lat = coor[0]
let long = coor[1]
print(lat)
print(long)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
}