1

I'm trying to make a slideshow with this library

https://github.com/zvonicek/ImageSlideshow

So i'm making a query, i bring some images and i append them here

var sliderArray = [UIImage]()
var testimg:UIImage!

let idaki = recipeObj.objectId
let pointer2 = PFObject(outDataWithClassName:"Recipes", objectId: idaki!)
let galquery = PFQuery(className:"sliderRecipes")
galquery.whereKey("recipe", equalTo: pointer2)
galquery.findObjectsInBackgroundWithBlock {
    (objects: [PFObject]?, error: NSError?) -> Void in


    if error == nil {
        // The find succeeded.
        print("Successfully retrieved \(objects!.count) scores.")
        // Do something with the found objects
        if let objects = objects {
            for object in objects {
                count += 1

                let glrimg = object["sliderImage"] as! PFFile
                glrimg.getDataInBackgroundWithBlock {
                    (imageData3: NSData?, error: NSError?) -> Void in
                    if error == nil {
                        if let imageData2 = imageData3 {
                            self.testimg = UIImage(data:imageData2)
                            print(self.testimg)
                            print(self.sliderArray)
                            self.sliderArray.append(UIImage(data:imageData2)!)




                        }
                        if count == objects.count { print(self.sliderArray) }
                    }
                }



                // print("test")
                // print(self.sliderPinakas)
            }
        }
    } else {
        // Log details of the failure
        print("Error: \(error!) \(error!.userInfo)")
}

And after all this i DONT have an array with images. In the print above it first shows the empty array and after that it shows the prints of UI Images that i want to show them like this to a slider

slideshow.setImageInputs([ImageSource(image: UIImage(named: "myImage"))!, ImageSource(image: UIImage(named: "myImage2"))!])

but instead of having to do it with the name, UIImage(named: "myImage"))! i would like to do it this way

self.slider.setImageInputs([ImageSource(image: self.testimg)]) 

for all the images of the array, cause the above line shows only one. Is there anyone that could help? Thanks!

1 Answer 1

1

You have pass to self.slider.setImageInputs array of all objects ImageSource [ImageSource(image: self.testimg1), ImageSource(image: self.testimg2), ...] etc., not only one object [ImageSource(image: self.testimg)].

If you add images like:
self.slider.setImageInputs([ImageSource(image: self.testimg)])
self.slider.setImageInputs([ImageSource(image: self.testimg2)])
you'll simply replace first image with second.

Create new array, enumerate all images from sliderArray, and append they to array ImageSource(image: self.testimg1) objects.

Also remember, you have to call this from block glrimg.getDataInBackgroundWithBlock!

add before for

var count = 0

and add inside block

count +=1
if count == objects.count {
    print(self.sliderArray)
}.

That will print array when all objects finished loads (they can loads in chaotic order).

Sign up to request clarification or add additional context in comments.

16 Comments

could you see any issue of the first sliderArray ? Because i append images but it shows me an emty array after all
and where you declare self.testimg?
What do you get from print("Successfully retrieved \(objects!.count) scores.")?
from print(self.testimg)?
i get the UIImage that is being downloaded from parse. Although it prints first the array and then the images... that means that it didnt have the time to append them !
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.