嗨,我是一般的快速和编码的新手,请原谅我,如果我不理解或提出愚蠢的问题。 我试图在地图上保存用户广告的引脚,我不知道如何,这是我的代码到目前为止,引脚已添加,但当我关闭应用程序并重新打开它时,应用程序“忘记”该引脚: }
func action(gestureRecognizer:UIGestureRecognizer) {
if (gestureRecognizer.state == UIGestureRecognizerState.Began) {
var touchPoint = gestureRecognizer.locationInView(self.mapView)
var newCoordinate: CLLocationCoordinate2D = mapView.convertPoint(touchPoint, toCoordinateFromView: self.mapView)
var newAnnotation = MKPointAnnotation()
newAnnotation.coordinate = newCoordinate
newAnnotation.title = "new place"
newAnnotation.subtitle = "subtitle"
mapView.addAnnotation(newAnnotation)
}
我尝试在viewdidload中添加它但它不起作用所以我可能有错误: `
NSUserDefaults.standardUserDefaults().setObject("newAnnotation", forKey: "newCoordinate")
NSUserDefaults.standardUserDefaults().objectForKey("newAnnotation")