NYTPhotoViewer
NYTPhotoViewer copied to clipboard
initWithPhotos: replacement?
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?
[[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];
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
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?
__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.
The number of images is right but can't swipe between images, hope you can figure this problem
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 {
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.
I had this problem after you release the new version 2.0.0
, so I suggest you can review the new code.
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?
- (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.
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.