Add datasource
preview.dataSource = self;
And add the delegate method.
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
Your problem solved.
题
i got a uicollectionsview
when i select i image from there i want it to show in the Quicklook i think i got it to select the file prober but showing it crashes the app with this message :
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0xb7be9c0'
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didselect");
QLPreviewController * preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.currentPreviewItemIndex = indexPath.row;
[self presentViewController:preview animated:YES completion:Nil];
}
#pragma mark -
#pragma mark QLPreviewControllerDelegate methods
- (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id <QLPreviewItem>)item {
return YES;
}
#pragma mark -
#pragma mark QLPreviewControllerDataSource methods
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return [photoURLsLargeImage count];
}
this is where my problem is, i think:
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
NSString *entry = [photoURLsLargeImage objectAtIndex:index];
return [NSURL fileURLWithPath:entry];
}
photoURLsLargeImage is a nsmutablearray with at least 17 objects fetched from flickr
解决方案
Add datasource
preview.dataSource = self;
And add the delegate method.
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
Your problem solved.
其他提示
You should use this currentPreviewItemIndex
:
The index, within the preview item navigation list, of the item currently displayed in the Quick Look preview controller. You can change which item is displayed, among those in a navigation list, by setting this property’s value. If no item is being displayed, this property’s value is NSNotFound.