NYTPhotoViewer icon indicating copy to clipboard operation
NYTPhotoViewer copied to clipboard

I can not turn pages when using the new API

Open LayChan opened this issue 7 years ago • 4 comments

Hello, I can not turn pages when using this method:

NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:photos];
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithDataSource:dataSource initialPhoto:photoM delegate:nil];
[self presentViewController:photosViewController animated:NO completion:nil];

How do i solve this problem? thanks

LayChan avatar Feb 03 '18 01:02 LayChan

I asked for more info here: https://github.com/NYTimes/NYTPhotoViewer/issues/258#issuecomment-362786643

jamesstout avatar Feb 04 '18 11:02 jamesstout

Facing the same issue. It seems like _dataSource in NYTPhotosViewController is being set to nil. And when this delegate method is called, it finds the self.dataSouce as nil.

    NSUInteger photoIndex = [self.dataSource indexOfPhoto:viewController.photo];
    if (photoIndex == NSNotFound) {
        return nil;
    }

    return [self newPhotoViewControllerForPhoto:[self.dataSource photoAtIndex:(photoIndex + 1)]];
}

Please fix this issue. Thanks

ehsan-ff avatar Feb 11 '18 19:02 ehsan-ff

Just in case you guys didn't figure it out, the data source is a weak reference. You need to be holding onto it the calling class so that the reference sticks around long enough.

StainlessStlRat avatar May 25 '18 10:05 StainlessStlRat

@StainlessStlRat Thanks!, I used a strong reference, now it works. Guys, you should use strong reference of the Data Source.

algenepulido avatar Jun 21 '18 08:06 algenepulido