Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios mapView未加载到容器中_Ios_Swift_Mkmapview - Fatal编程技术网

Ios mapView未加载到容器中

Ios mapView未加载到容器中,ios,swift,mkmapview,Ios,Swift,Mkmapview,我有一个UIViewController,它有一个分段的控制器,从这个VC我有两个容器。容器1加载一个tableview,效果很好,容器2设置了一个MKMapView,但没有加载,只是在我为它选择段时有一个空白屏幕 这是我的TrackMapView代码 import UIKit import MapKit class TrackMapView: UIViewController { @IBOutlet weak var mapView: MKMapView! override func

我有一个UIViewController,它有一个分段的控制器,从这个VC我有两个容器。容器1加载一个tableview,效果很好,容器2设置了一个MKMapView,但没有加载,只是在我为它选择段时有一个空白屏幕

这是我的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(按预期工作)

此代码下面还有许多函数


我的任何ViewController中都没有任何Segue代码,这都是通过情节提要完成的。

好,现在解决了。我在故事板上的mapview下面似乎有一个错误的视图,删除了mapview和独立视图,重新添加了mapview,它工作正常


感谢所有的输入

您在哪里声明了
mapContainer
。显示代码。在我的主视图控制器中,使用以下“@IBOutlet-weak-var-mapContainer:UIView!”“@IBOutlet-weak-var-tableContainer:UIView!”这些都连接到故事板中相应的容器。您如何将
trackmappview
添加到
mapContainer
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()


}