2016-11-12 2 views
0

私はSwiftの新機能で、このコードでスタックされ、私のところに戻ってくるたびに "ユーザー入力領域とユーザー出口領域の未解決識別子 'showAlert'の使用:あなたは「showAlert()」関数を使用している場合未解決の識別子 'showAlert'の使用Swift

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 LET警告= UIAlertController(タイトル:タイトル、メッセージ:nilに、preferredStyle:.alert) \t \t alert.addAction(UIAlertAction(タイトル: "キャンセル" を、スタイル:.DEFAULT、ハンドラ:{(アクション) \t \t \t alert.dismiss(アニメーション:真、終了:ゼロ)で \t \t})) \t \t self.present(アラート、アニメーション:真、完了: nil) \t} これは今のところうまくいくようですしかし彼らは私に戻ります:スレッド6:シグナルSIGABRT –

答えて

0

私は知りませんが、あなたは、ユーザーに警告しようとしているならば、あなたはこのようにそれを行うことができます。

//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) 
} 
関連する問題