mariohahn / MHVideoPhotoGallery

A Photo and Video Gallery
MIT License
1.96k stars 353 forks source link

Crash when not using as modal #144

Open dvkch opened 8 years ago

dvkch commented 8 years ago

Hi,

I tried using MHGalleryController as per the example except that I present it in a UISplitViewController and not modally. The app crashed at startup on the following line :

    MHGalleryItem *item = [self itemForIndex:self.pageIndex];

    MHImageViewController *imageViewController = [MHImageViewController imageViewControllerForMHMediaItem:item viewController:self];
    imageViewController.pageIndex = self.pageIndex;
    [self.pageViewController setViewControllers:@[imageViewController] // <-- CRASH
                                      direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO
                                     completion:nil];

After a while I figured out the datasource property on MHGalleryImageViewerViewController was nil, leading to a nil item and a nil imageViewController.

I explored the details of -[UIViewController(MHGalleryViewController) presentMHGalleryController:animated:completion:]and realized it assigned the controller itself as a datasource if no datasource is set, and replicating this behavior fixed my crash.

I would strongly suggest that this be done by default when setting the items array property of the main controller or when no datasource is set, or at least be explained in the doc to prevent further issues since this seams like a basic use of the component.

Thanks for considering