【发布时间】:2016-03-16 12:59:39
【问题描述】:
编辑 1:我已经重组了我的 ViewController 以便更轻松地完成我想要完成的工作。
编辑 2:我意识到在我的代码中添加注释时缺少一些重要的东西,另一个函数覆盖了第一个 segue。
这个 ViewController 是创建注解的地方;从这个视图中我需要的只是将 touchMapCoordinates 传输到另一个 ViewController,这样我就可以将 PFGeoPoint 保存在一个数组中。
编辑 3 经过长时间的了解正在发生的事情并简化代码后,我得出了基于 Swift- variable not initialized before use (but it's not used) 的最终结论,即我尝试使用的当前方法在任何情况下都不起作用或由于场景对其进行异步保存。如果有人知道解决方法,那么您已经正式完成了以前没有做过的事情:)。
出现的错误是
在初始化之前使用常量“boi”
在 Appdata 中声明的子类可在项目中的任何位置使用
import Foundation
import Parse
import MapKit
class MyAnnotation: PFObject, PFSubclassing, MKAnnotation {
// MARK: - Properties
@NSManaged var location: PFGeoPoint
// MARK: - Initializers
init(coordinate: CLLocationCoordinate2D) {
super.init()
self.location = PFGeoPoint(latitude: coordinate.latitude, longitude: coordinate.longitude)
print(location)
}
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
// MARK: - PFSubclassing protocol
static func parseClassName() -> String {
return "AnnotationPins"
}
// MARK: - MKAnnotation protocol
var coordinate: CLLocationCoordinate2D {
return CLLocationCoordinate2DMake(location.latitude, location.longitude)
}
var 标题:字符串? = "开始主题"
}
代码将全部异步保存在哪里
} else {
let imageData = UIImagePNGRepresentation(self.galleryCameraImage.image!)
let parseImageFile = PFFile(name: "upload_image.png", data: imageData!)
let boi : MyAnnotation
let textTitleandText = PFObject(className: "AnnotationPins")
textTitleandText["textTopic"] = userTopic.text
textTitleandText["textInformation"] = userText.text
textTitleandText["userUploader"] = PFUser.currentUser()
textTitleandText["imageFile"] = parseImageFile!
textTitleandText["location"] = boi.location
textTitleandText.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
if error == nil {
如果有人能提供帮助,将不胜感激!
【问题讨论】:
标签: ios swift parse-platform mkannotation pfsubclassing