I am using KTPhotoBrowser
in order to display images parsed from a server.
Also, I am sharing the image by using Share kit. The sharing works fine when I am using the PhotoDataSource
NSObject
class in the KTPhotoBrowser
.
However, if I use SDWebImageDataSource
NSObject
class to share the images by Share kit, it crashes when I press the action sheet button saying
Terminating app due to uncaught exception NSInvalidArgumentException, reason:
->[SDWebImageDataSource imageAtIndex:]: unrecognized selector sent to instance 0x8682e10
I am able to display the image in the scroll view.
I have used the following code in when I press the action sheet. In the KTPhotoScrollViewController
class.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == actionSheet.cancelButtonIndex) return;
NSDictionary *table = [[NSDictionary alloc] initWithObjectsAndKeys:@"SHKTwitter", @"Twitter", @"SHKFacebook", @"Facebook", @"SHKMail", SHKLocalizedString(@"Email", nil), nil];
NSString *sharersName = [actionSheet buttonTitleAtIndex:buttonIndex];
Class SharersClass = NSClassFromString([table objectForKey:sharersName]);
[table release];
NSLog(@"dataaaasrc-- %@",dataSource_);
UIImage *image = [dataSource_ imageAtIndex:currentIndex_];
SHKItem *item = [SHKItem image:image title:@"Look at this picture!"];
[SharersClass performSelector:@selector(shareItem:) withObject:item];
}
In the NSLog I got the following:
dataaaasrc--SDWebImageDataSource: 0x8682e10 //betwn lessthan and greater than symbols
-[SDWebImageDataSource imageAtIndex:]: unrecognized selector sent to instance 0x8682e10
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDWebImageDataSource imageAtIndex:]: unrecognized selector sent to instance 0x8682e10'
*** First throw call stack:
I managed to make a "Save Image" button, the same place where you want your sharekit button by using some code from a sample that comes with KTPhotoBrowser. (I looked in the TabBarSample with FlickrSample)
In SDWebImageDataSource.m I added this:
- (UIImage *)imageWithURLString:(NSString *)string {
NSURL *url = [NSURL URLWithString:string];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
return image;
}
- (UIImage *)imageSourceAtIndex:(NSInteger)index {
NSArray *imageUrls = [images_ objectAtIndex:index];
NSString *url = [imageUrls objectAtIndex:FULL_SIZE_INDEX];
return [self imageWithURLString:url];
}
In KTPhotoBrowserDataSource.h:
- (UIImage *)imageSourceAtIndex:(NSInteger)index;
Then you can make your call like this:
UIImage *image = [dataSource_ imageSourceAtIndex:currentIndex_];