Reload photos in Apple's "PhotoScroller" sample code app

Discussion in 'iOS Programming' started by tsuru, Dec 5, 2011.

  1. tsuru, Dec 5, 2011
    Last edited: Dec 5, 2011

    tsuru macrumors member

    Dec 14, 2008
    I'm working with Apple's PhotoScroller sample code app.

    In Apple's original code, a couple images are loaded into the scrollview from the application bundle via a plist (also in the bundle) that contains the image names.

    I've modified the code to use ARC and allow new images to be added via UIImagePickerController. And instead of the images and plist being loaded from the app's bundle, they are loaded from the app's "Documents" folder.

    Everything is working fine, except when I add a new image, the app must be restarted before it updates the scrollview allowing you to see the added image.

    I'm guessing there's a method somewhere that I can call that will update the scrollview's data, but I've poured over Apple's code and haven't been able to find it. Does anyone know which method it is that needs to be called, or if a new one needs to be written, how I would go about doing that?

    I've attached my modified version of the PhotoScroller app.

    Attached Files:

  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    I don't think it's something like "reload", i think you just need to rerender your view, reloadInputViews or something. Not sure.. I mostly use something like MWPhotoBrowser, or similair.
  3. tsuru thread starter macrumors member

    Dec 14, 2008
    Thanks for the suggestions jnoxx. I actually did try reloadInputViews but that didn't work. I'm sure it's something simple, but I just don't know where to look for it. Anyone, any other suggestions?
  4. tsuru thread starter macrumors member

    Dec 14, 2008
    I figured out one part. With the following code changes (if there's more than one image already loaded so that you can swipe between images) adding a new image will insert a new image at the end of the scroll view which you can partially see by dragging the last image. So now the image is added to the scrollview but the scroll view paging isn't updated to reflect that yet.

    Does this give anyone any ideas for the solution?

    - (NSArray *)imageData {
        // The following line of code was to load the image data array only once so I commented it out
        // static NSArray *__imageData = nil;
        static NSArray *__imageData; // I added this one instead
        //Since I want to load the imageData array more than once I commented out the if statement
        //if (__imageData == nil) {
            // read the filenames/sizes out of a plist in the app bundle
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSString *path = [documentsDirectory stringByAppendingPathComponent:[@"ImageData" stringByAppendingPathExtension:@"plist"]];
            //NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"];
            NSData *plistData = [NSData dataWithContentsOfFile:path];
            NSString *error; NSPropertyListFormat format;
            __imageData = [NSPropertyListSerialization propertyListFromData:plistData
            if (!__imageData) {
                NSLog(@"Failed to read image names. Error: %@", error);
                //[error release];
        return __imageData;
    - (NSUInteger)imageCount {
        // The following line of code was to count the images only once, so I commented it out 
        // static NSUInteger __count = NSNotFound;
        static NSUInteger __count; // I added this one instead
        //Since I want to count the images more than once, I commented out the if statement
        //if (__count == NSNotFound) {
            __count = [[self imageData] count];
        return __count;
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I've used this sample code in a couple projects. It is, as written, somewhat inflexible and has some bugs. I made it work with a navbar. With that it works like other view controllers. To reset it my code creates a new one from scratch. The image list should be an ivar, not a static object like in the sample code. Throw away that plist junk and just make it a property of the view controller and then you can add or remove images from it more easily. If you add/remove an image you probably need to reset the frame of the main scrollview and also retile the images.

Share This Page