0
我有一个UIViewController有一个分段控制器,从这个VC我有2个容器。容器1加载一个tableview并且工作得很好,容器2有一个MKMapView的设置但不加载,只是当我为它选择一个段时有一个空白屏幕。mapView未加载容器
这是我的TrackMapView代码。
import UIKit
import MapKit
class TrackMapView: UIViewController {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.mapType = MKMapType.standard
let location = CLLocationCoordinate2D(latitude: 23.0225,longitude: 72.5714)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
mapView.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "jim"
annotation.subtitle = "smith"
mapView.addAnnotation(annotation)
}
}
这是我的段码,
@IBAction func showContainer(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.5, animations: {
self.tableContainer.alpha = 1
self.mapContainer.alpha = 0
})
}else {
UIView.animate(withDuration: 0.5, animations: {
self.tableContainer.alpha = 0
self.mapContainer.alpha = 1
})
}
}
类是正确连接到容器中的故事板和IBOutlets似乎在正确的地方连接起来。
TrackTableView(其按预期方式工作)
import UIKit
import GoogleMobileAds
import FirebaseDatabase
import CoreLocation
import MapKit
class TrackTableView: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
var TR: newTracks!
var track = [newTracks]()
var items: [newTracks] = []
var filteredTrack = [newTracks]()
var inSearchMode = false
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
searchBar.delegate = self
searchBar.returnKeyType = UIReturnKeyType.done
getTrackData()
}
有许多的低于该代码也函数。
我没有任何ViewControllers中的Segue代码,它都是通过storyboard完成的。
你在哪里宣布'mapContainer'。显示代码。 –
在我的主ViewController与以下 “@IBOutlet弱var mapContainer:UIView!” “@IBOutlet weak var tableContainer:UIView!” 这些连接到故事板中的相应容器 –
如何将'TrackMapView'添加到'mapContainer'? –