2016-10-04 181 views
-3

我想編寫一個應用程序,用戶可以通過按下地圖在地圖上放置圖釘。引腳掉線後,我想將引腳保存到數據庫中。我不在乎哪一個可能與RealmCoreData如何在地圖視圖上放置註釋並保存銷

+0

我認爲這是一個完美的教程爲你https://www.raywenderlich.com/112544/realm-tutorial-getting-started。在那裏你用Realm創建一個基於地圖的應用程序作爲數據存儲 – ronatory

+0

本教程似乎完美謝謝你。我現在就試試 –

回答

0

RTFM

不能真正幫助你無需任何代碼或任何問題。

一些鏈接,可以是有益的: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/index.html https://developer.apple.com/reference/corelocation https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009497

回來你試一下後;)

編輯:

您已定義viewDidLoad方法內手勢識別,把它直接在你的控制器中,而應該刪除一些錯誤:

import UIKit 
import MapKit 

class ViewController: UIViewController { 

    @IBOutlet var mapView: MKMapView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Create a gesture recognizer for long presses (for example in viewDidLoad) 
     UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
     lpgr.minimumPressDuration = 0.5; //user needs to press for half a second. 
     [self.mapView addGestureRecognizer:lpgr]; 
    } 

    - (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer { 
     if (gestureRecognizer.state != UIGestureRecognizerStateBegan) { 
      return; 
     } 
     CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView]; 
     CLLocationCoordinate2D touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView]; 
     MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; 
     point.coordinate = touchMapCoordinate; 
     for (id annotation in self.mapView.annotations) { 
      [self.mapView removeAnnotation:annotation]; 
     } 
     [self.mapView addAnnotation:point]; 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 
} 
+0

我現在在UILongPressGestureRecognisezer * lpgr行中的表達式列表中獲得Error expected表達式,並在行中出現預期的錯誤聲明 - (void)handleLongPress:...我真的不知道是什麼我的代碼錯誤 –

+0

有一個等號丟失 –

相關問題