【发布时间】:2023-03-28 20:07:01
【问题描述】:
所以我有一个包含 tableView 的视图控制器。每当单击 tableview 单元格时,就会推入另一个视图控制器。这个新的视图控制器有自己的 xib。文件和快速文件。我在新的视图控制器中有一个地图视图,但新的视图控制器在推入时是黑色的。我该如何解决这个问题? TableView didSelectRowAtIndexPath 方法:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as BusinessTableViewCell
var business = self.results[indexPath.row]
var mapView = BusinessMapViewController()
mapView.business = business
mapView.mapView = MKMapView()
self.navigationController?.pushViewController(mapView, animated: true)
println("\(business.name) SELECTED")
}
新视图控制器:
import UIKit
import MapKit
class BusinessMapViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
var business:Business!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let location = CLLocationCoordinate2D(
latitude: 37.774929,
longitude: -122.419416
)
let span = MKCoordinateSpanMake(0.1, 0.1)
let region = MKCoordinateRegion(center: location, span: span)
println(business.latitude)
mapView.setRegion(region, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】:
-
你解决过这个问题吗?我面临着同样的问题;在我嵌入 navigationController 或将 mapView 推入之前,mapView 显示良好。