Ios 如何强制异步保存常量子类?
编辑1:我已重新调整了ViewController,使其更容易完成我想要的操作 编辑2:我意识到在代码中添加注释时缺少了一些主要内容,另一个函数覆盖了第一个序列 此ViewController是创建注释的位置;从这个视图中,我只需要将TouchMap坐标传输到另一个ViewController,这样我就可以将PFGeoPoint保存在一个数组中 编辑3 经过长时间的理解和简化代码后,我得出了基于的最终结论,即我尝试使用的当前方法在任何情况下都不起作用,因为它是异步保存的。如果有人知道一个解决方法,那么你已经正式做了一些以前没有做过的事情:) 显示的错误是 初始化前使用的常量“boi” 在Appdata中声明用于项目中任何位置的子类Ios 如何强制异步保存常量子类?,ios,swift,parse-platform,mkannotation,pfsubclassing,Ios,Swift,Parse Platform,Mkannotation,Pfsubclassing,编辑1:我已重新调整了ViewController,使其更容易完成我想要的操作 编辑2:我意识到在代码中添加注释时缺少了一些主要内容,另一个函数覆盖了第一个序列 此ViewController是创建注释的位置;从这个视图中,我只需要将TouchMap坐标传输到另一个ViewController,这样我就可以将PFGeoPoint保存在一个数组中 编辑3 经过长时间的理解和简化代码后,我得出了基于的最终结论,即我尝试使用的当前方法在任何情况下都不起作用,因为它是异步保存的。如果有人知道一个解决方法
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)
}
变量标题:字符串?=“开始主题”
}
其中代码将全部异步保存在一起
} 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 {
如果有人能帮忙,我将不胜感激 让我们将您的
位置数据
视为通过分段传输的正常数据。
您可以使用此方法配置将保存位置数据的目标视图控制器变量(相同类型)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//check your segue name
if segue.identifier == "YourSegueIdentifier" {
let destinationVC = segue.destinationViewController as! YourDestinationViewController
destinationVC.locationVariableInDestinationVC = locationVariableInCurrentVC
}
}
以上是通过segue传递数据的最简单方法,您也可以对位置数据使用相同的方法
希望有帮助
更新:基于您更新的代码
将func prepareforsgue(segue:UIStoryboardSegue,sender:AnyObject?{}
移出handleLongPress
函数<代码>PrepareForSegue函数在有任何通过分段的导航时自动调用
如果您想以编程方式启动segue导航,则为segue分配一个标识符,然后只需调用
self.performsguewithidentifier(“您的segue标识符”,发送者:nil)
越程prepareforsgue
方法,如下所示
override func prepareForSegue(segue: UIStoryboardSegue, sender:
AnyObject?) {
if segue.identifier == "SegueID" {
let destinationVC = segue.destinationViewController as! DestinationViewController
// Create property in destinationView controller & assign required data from here.
}
}
希望有帮助。
}重写func Prepareforsgue(segue:UIStoryboardSegue,sender:AnyObject?{if segue.identifier==“China”{let destinationVC=segue.destinationViewController as!AnnotationViewController destinationVC.location=MyAnnotation}
因此,在代码中,我不断得到错误,类型“ViewController”没有成员位置。您必须在目标视图控制器中添加位置变量,该变量将保存您的数据。这就像是给目标视图控制器中可用的变量赋值一样。。希望有意义:)`var locationdata=PFGeoPoint()`所以我在目标viewcontroller中有它,但当我将它设置为它时它仍然不起作用,=地图viewcontroller中的locationdata您的myAnnotation
变量是PFGeoPoint类型吗?正如您所声明的那样,我已经用更新的问题更新了代码,我一直在尝试全面解决这个问题,MyAnnotation是PFGeoPoint的一个变量。我已经更新了代码,以准确地模拟我当前的情况。