PFObjects没有保存在数据库中

时间:2014-11-14 19:32:48

标签: ios iphone swift parse-platform

我试图将项目保存在" Items" "图像"中的类和几个图像;类。在此之后,我想在" Items"中创建列图片之间的关系。并指向我刚添加的图像。我试过跟随,但它根本没有添加任何东西。好像没有调用saveInBackgroundBlock?

@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")
    }
}

0 个答案:

没有答案