Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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
Swift 用户默认保存mapType UISegmentedControl_Swift_Mkmapview_Uisegmentedcontrol - Fatal编程技术网

Swift 用户默认保存mapType UISegmentedControl

Swift 用户默认保存mapType UISegmentedControl,swift,mkmapview,uisegmentedcontrol,Swift,Mkmapview,Uisegmentedcontrol,我需要将MapView地图类型保存在UISegmentedControl中。代码仅将选定的地图类型保存在UISegmentedControl中,而不是MapView中的地图类型。这是我的密码: @IBAction func standard(_ sender: UISegmentedControl) { switch maptypes.selectedSegmentIndex { case 0: self.mapView.mapType =

我需要将
MapView
地图类型保存在
UISegmentedControl
中。代码仅将选定的地图类型保存在
UISegmentedControl
中,而不是
MapView
中的地图类型。这是我的密码:

@IBAction func standard(_ sender: UISegmentedControl) {

        switch maptypes.selectedSegmentIndex {
        case 0:
           self.mapView.mapType = .hybrid

             UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")

        case 1:

            self.mapView.mapType = .standard
        UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")

        case 2:

            UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")
            self.mapView.mapType = .satellite
        default:
            break;
        }
    }
override func viewDidLoad() {
        super.viewDidLoad()

if let value = UserDefaults.standard.value(forKey: "selectedMapType"){
            let selectedIndex = value as! Int
            maptypes.selectedSegmentIndex = selectedIndex
        }
}

将其设置为函数并在
viewDidLoad
和action中调用

func shared () {

  switch maptypes.selectedSegmentIndex {
    case 0:
       self.mapView.mapType = .hybrid

         UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")

    case 1:

        self.mapView.mapType = .standard
    UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")

    case 2:

        UserDefaults.standard.set(maptypes.selectedSegmentIndex, forKey: "selectedMapType")
        self.mapView.mapType = .satellite
    default:
        break;
    }
}
//

@IBAction func standard(_ sender: UISegmentedControl) {

   shared()
}
override func viewDidLoad() {
        super.viewDidLoad()

       if let value = UserDefaults.standard.value(forKey: "selectedMapType"){
            let selectedIndex = value as! Int
            maptypes.selectedSegmentIndex = selectedIndex
            shared()
       }
}