0

I'm using MWPhotoBrowser to display a single image in my app. I've set the class of my view controller to MWPhotoBrowser in the main storyboard and I've added the following code but the image fails to load.

    let photos = NSMutableArray()
    let photo = MWPhoto(URL: NSURL(string: "http://images.nationalgeographic.com/wpf/media-live/photos/000/911/cache/man-ocean-phytoplankton_91111_600x450.jpg"))
    photos.addObject(photo)


    self.photos = photos
    self.displayActionButton = true
    self.displayActionButton = true;
    self.displayNavArrows = true;
    self.displaySelectionButtons = true;
    self.alwaysShowControls = true;
    self.zoomPhotosToFill = true;
    self.enableGrid = true;
    self.startOnGrid = true;
    self.enableSwipeToDismiss = true;

And these are the delegate methods. I noticed that we need a photoAtIndex which returns an MWPhoto but the delegate only has a function which returns an MWPhotoProtocol

    func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> UInt
{
    return UInt(photos.count)
}
func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol!
{
    return photos.objectAtIndex(Int(index)) as! MWPhotoProtocol
}

I get the following screen:

enter image description here

Swapnil Dhanwal
  • 399
  • 2
  • 6
  • 17
  • `func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol! { return photos.objectAtIndex(Int(index)) as! MWPhotoProtocol }`is this method called? – Payal Maniyar Jun 02 '16 at 05:44

1 Answers1

1

First, MWPhoto conforms to MWPhotoProtocol, so instead you should do:

var photos = [MWPhoto]()
let photo = MWPhoto(URL: "...")
photos.append(photo)

You can then return photos[index] directly.

EDIT - You should be reading your console. Using the URL you provided, the following is logged:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

I changed your link to https and everything loaded fine.

sschale
  • 5,168
  • 3
  • 29
  • 36