Ios PFO对象未保存在数据库中
我试图在Items类中保存一个项目,在images类中保存几个图像。在此之后,我想在项目中的列图片之间创建一个关系,并指向我刚才添加的图像。我尝试了以下内容,但它没有添加任何内容。似乎没有调用saveInBackgroundBlockIos PFO对象未保存在数据库中,ios,iphone,swift,parse-platform,Ios,Iphone,Swift,Parse Platform,我试图在Items类中保存一个项目,在images类中保存几个图像。在此之后,我想在项目中的列图片之间创建一个关系,并指向我刚才添加的图像。我尝试了以下内容,但它没有添加任何内容。似乎没有调用saveInBackgroundBlock @IBAction func addToServer(sender: UIBarButtonItem) { var imageCell: ImageViewCell = tableView?.cellForRowAtIndexPath(NSIndexP
@IBAction func addToServer(sender: UIBarButtonItem) {
var imageCell: ImageViewCell = tableView?.cellForRowAtIndexPath(NSIndexPath(forRow: 1, inSection: 0)) as ImageViewCell
var adressCell: AdressViewCell = tableView?.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0)) as AdressViewCell
var contentCell: ContentViewCell = tableView?.cellForRowAtIndexPath(NSIndexPath(forRow: 2, inSection: 0)) as ContentViewCell
if imagePicked?.count > 0 && adressCell.adressField.text.length() > 0 && contentCell.priceField.text.length() > 0 && contentCell.contentField.text.length() > 0 && catBool == true {
var address = adressCell.adressField.text + ", Denmark"
var geocoder = CLGeocoder()
geocoder.geocodeAddressString(address, {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if let placemark = placemarks?[0] as? CLPlacemark {
var price = contentCell.priceField.text.toInt()
var categoryObject: PFObject = self.objectArray?.objectAtIndex(self.currentIndex!) as PFObject
var itemObject:PFObject = PFObject(className: "Items")
let coordinates = placemark.location.coordinate as CLLocationCoordinate2D
let geoPoint = PFGeoPoint(latitude: coordinates.latitude, longitude: coordinates.longitude)
itemObject.setObject(geoPoint, forKey: "location")
itemObject.setObject(contentCell.contentField.text, forKey: "description")
itemObject.setObject(price, forKey: "price")
itemObject.setObject(categoryObject, forKey: "category")
var relation:PFRelation = itemObject.relationForKey("pictures")
for var i = 0; i < self.imagePicked?.count; i++ {
var image:UIImage = self.imagePicked?.objectAtIndex(i) as UIImage
var imageObject = PFObject(className: "Images")
var imageData:NSData = UIImageJPEGRepresentation(image, 1.0)
var theFile = PFFile(data: imageData)
imageObject.setObject(theFile, forKey: "image")
imageObject.saveInBackgroundWithBlock {
(success: Bool!, error: NSError!) -> Void in
println("lol1")
if (success != nil) {
relation.addObject(imageObject)
itemObject.saveInBackground()
}
}
}
}
})
} else {
println("Please fill in all informations")
}
}
你试过设置断点并验证它是否被调用了吗?没有,但是因为printlnlol1没有被调用,我猜它没有被调用。那么你应该进行一些调试并确定该行是否被调用。缺少的打印文本表示未执行闭包,因此可能也未调用save方法。在循环中设置断点,如果它从未停止,请尝试使用外部断点,等等。代码不起作用可能有几个原因,因此首先尝试缩小范围,直到找到可以说是这一行代码的内容。没有这一点,很难找出问题所在。