NYTPhotoViewer icon indicating copy to clipboard operation
NYTPhotoViewer copied to clipboard

initWithPhotos: replacement?

Open guidev opened this issue 7 years ago • 10 comments

Hello, I've updated to v. 2.0 and I get compile errors:

No visible @interface for 'NYTPhotosViewController' declares the selector 'initWithPhotos:'

What's the new API?

guidev avatar Jan 30 '18 09:01 guidev

[[NYTPhotosViewController alloc] initWithDataSource:dataSource initialPhoto:nil delegate:self];

so you need to import NYTPhotoViewerArrayDataSource.h and init the new data source:

NYTPhotoViewerArrayDataSource *dataSource = [[NYTPhotoViewerArrayDataSource alloc] initWithPhotos:_photos];

jamesstout avatar Jan 31 '18 06:01 jamesstout

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 02 '18 02:02 LayChan

What's photoM? Is it a photo in dataSource?

You mean you can't swipe between images? Can you post screenshots or link to an example project?

jamesstout avatar Feb 03 '18 07:02 jamesstout

__block LMNYTPhoto *initialPhoto = nil;
    NSArray *photos = [imageViews.rac_sequence map:^id(UIImageView * imageView) {
        LMNYTPhoto *photo = [[LMNYTPhoto alloc] initWithImageView:imageView];
        if (imageView == initialImageView) {
            initialPhoto = photo;
        }

        return photo;
    }].array;
    
    NYTPhotoViewerArrayDataSource *dataSource = [NYTPhotoViewerArrayDataSource dataSourceWithPhotos:photos];
    NYTPhotosViewController *viewController = [[NYTPhotosViewController alloc] initWithDataSource:dataSource initialPhoto:initialPhoto delegate:self];
    viewController.rightBarButtonItem = nil;
    [self.navigationController presentViewController:viewController animated:YES completion:nil];

This is how I use. e82245e5-a0b5-43eb-9fa8-f4e1deacf4ef The number of images is right but can't swipe between images, hope you can figure this problem

KeepFish avatar Feb 06 '18 02:02 KeepFish

I don't know much about reactiveCocoa, but you say photos is initialised with the right number of objects, your subclass LMNYTPhoto. Something is strange though as you set viewController.rightBarButtonItem = nil; but the share button is still showing.

I'd add logging to see what's in photos and dataSource and add breakpoints in - (void)photosViewController:(NYTPhotosViewController *)photosViewController didNavigateToPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex{ and - (void)didNavigateToPhoto:(id <NYTPhoto>)photo {

jamesstout avatar Feb 07 '18 02:02 jamesstout

I'm sorry about that viewController.rightBarButtonItem is showing because in this photo I had not set rightBarButtonItem = nil.

@import NYTPhotoViewer;

#import <Foundation/Foundation.h>

@interface LMNYTPhoto : NSObject <NYTPhoto>

@property (nonatomic) UIImageView *imageView;
@property (nonatomic) UIButton *button;

@property (nonatomic) UIImage *image;
@property (nonatomic) NSData *imageData;
@property (nonatomic) UIImage *placeholderImage;
@property (nonatomic) NSAttributedString *attributedCaptionTitle;
@property (nonatomic) NSAttributedString *attributedCaptionSummary;
@property (nonatomic) NSAttributedString *attributedCaptionCredit;

- (instancetype)initWithImageView:(UIImageView *)imageView;
- (instancetype)initWithButton:(UIButton *)button;

@end

@implementation LMNYTPhoto

- (instancetype)initWithImageView:(UIImageView *)imageView {
    if (self = [super init]) {
        self.imageView = imageView;
    }
    return self;
}

- (instancetype)initWithButton:(UIButton *)button {
    if (self = [super init]) {
        self.button = button;
    }
    return self;
}

@end

This is LMNYTPhoto I add 2 property just want use'd in

- (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController referenceViewForPhoto:(LMNYTPhoto *)photo {
    return photo.imageView;
 //   return photo.button;
}

I had add breakpoints in - (void)photosViewController:(NYTPhotosViewController *)photosViewController didNavigateToPhoto:(id <NYTPhoto>)photo atIndex:(NSUInteger)photoIndex but it don't go into this method.

KeepFish avatar Feb 07 '18 07:02 KeepFish

I had this problem after you release the new version 2.0.0, so I suggest you can review the new code.

KeepFish avatar Feb 07 '18 07:02 KeepFish

so I suggest you can review the new code.

I don't know man, I'm just trying to help, it's not my code.

Where do you set the image property of LMNYTPhoto?

jamesstout avatar Feb 08 '18 06:02 jamesstout

- (void)setImageView:(UIImageView *)imageView {
    if (_imageView != imageView) {
        _imageView = imageView;
        
        if (imageView) {
            RAC(self, image) = RACObserve(imageView, image);
        }
    }
}

Same with button property, sorry I thought you are author.

KeepFish avatar Feb 08 '18 07:02 KeepFish

I have found the solution.

 NYTPhotoViewerArrayDataSource *dataSource = [NYTPhotoViewerArrayDataSource dataSourceWithPhotos:photos];
    NYTPhotosViewController *viewController = [[NYTPhotosViewController alloc] initWithDataSource:dataSource initialPhoto:initialPhoto delegate:self];
    viewController.rightBarButtonItem = nil;
    [self.navigationController presentViewController:viewController animated:YES completion:nil];

When code go out this method (the {}) dataSource set to nil by system. So the NYTPhotosViewController can't find the rest photos just show initialPhoto or first photo. So if the dataSource is property of self and is strong it can't be release earlier, everything will work fine. Thanks to @jamesstout at the same time. Hope this can help you.

KeepFish avatar Feb 09 '18 07:02 KeepFish