2016-11-12 53 views
0

我在斯威夫特新的,我堆放着每次回到我的時候這段代碼和「對用戶使用未解決的標識符‘showAlert’的輸入區域和用戶出口區域:使用未解決的標識符「showAlert」斯威夫特

func setupData() { 
     // 1. check if system can monitor regions 
     if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) { 

      // 2. region data 
      let title = "Primo punto" 
      let coordinate = CLLocationCoordinate2DMake(38.121973, 13.360855) 
      let regionRadius = 300.0 

      // 3. setup region 
      let region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: coordinate.latitude, 
                     longitude: coordinate.longitude), radius: regionRadius, identifier: title) 
      locationManager.startMonitoring(for: region) 

      // 4. setup annotation 
      let restaurantAnnotation = MKPointAnnotation() 
      restaurantAnnotation.coordinate = coordinate; 
      restaurantAnnotation.title = "\(title)"; 
      mapView.addAnnotation(restaurantAnnotation) 

      // 5. setup circle 
      let circle = MKCircle(center: coordinate, radius: regionRadius) 
      mapView.add(circle) 
     } 
     else { 
      print("System can't track regions") 
     } 
    } 

    // 6. draw circle 
    func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer { 
     let circleRenderer = MKCircleRenderer(overlay: overlay) 
     circleRenderer.strokeColor = UIColor.red 
     circleRenderer.lineWidth = 1.0 
     return circleRenderer 
    } 

    // 1. user enter region 
    func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) { 
     showAlert("enter \(region.identifier)") 
    } 

    // 2. user exit region 
    @nonobjc func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) { 
     showAlert("exit \(region.identifier)") 
    } 
} 
+1

是什麼showAlert()?你有沒有在你的項目中使用這個名字創建任何方法? – PGDev

+0

我有這樣的功能:\t FUNC showAlert(標題:字符串){ \t \t設警報= UIAlertController(標題:標題,消息:無,preferredStyle:.alert) \t \t alert.addAction(UIAlertAction(標題: 「取消」 ,風格:.DEFAULT,處理程序:{(動作)在 \t \t \t alert.dismiss(動畫:真,完成:無) \t \t})) \t \t self.present(警報,動畫:真,完成:無) \t} 而現在看來工作但他們回到我身邊:線程6:SIGABRT信號 –

回答

0

我不知道,如果你有一個'showAlert()函數,但如果你想提醒用戶,那麼你可以做這樣的:

//Create alert 
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert) 

// Add action buttons to the alert 
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)) 

// Present the alert to the view 
self.present(alert, animated: true, completion: nil) 

,如果你想將其作爲一個函數,然後創建一個名爲show alerts的函數,並將自己的參數添加到該函數中,如下所示:

func showAlert(Title: String, Message: String) { 
    let alert = UIAlertController(title: Title, message: Message, preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)) 
    self.present(alert, animated: true, completion: nil) 
}