Objective c QLViewController仅显示单个文件
我正在使用QLPreviewController显示一组文件。然而,它只显示第一个,而我似乎无法滑动或做任何事情来显示第二个。我做错了什么?我必须手动设置吗?如果是的话,我该怎么做呢 这是来自我的AppDelegate.m:Objective c QLViewController仅显示单个文件,objective-c,ios,events,qlpreviewcontroller,Objective C,Ios,Events,Qlpreviewcontroller,我正在使用QLPreviewController显示一组文件。然而,它只显示第一个,而我似乎无法滑动或做任何事情来显示第二个。我做错了什么?我必须手动设置吗?如果是的话,我该怎么做呢 这是来自我的AppDelegate.m: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // normal viewcontroll
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// normal viewcontroller init here
[self showPreview] ;
return YES;
}
NSArray* documents ;
QLPreviewController* preview ;
- (void) showPreview
{
documents = [[NSArray alloc] initWithObjects: @"photo" , @"photo2" , nil ] ;
preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.delegate = self;
preview.view.frame = [[UIScreen mainScreen] bounds];
//save a reference to the preview controller in an ivar
// self.previewController = preview;
//refresh the preview controller
[preview reloadData];
[[preview view] setNeedsLayout];
[[preview view] setNeedsDisplay];
[preview refreshCurrentPreviewItem];
preview.view.userInteractionEnabled = YES;
//add it
[self.viewController.view addSubview:preview.view];
}
我还在同一个AppDelegate.m文件中声明了两个回调函数:
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
NSString* filename = [documents objectAtIndex:index] ; // @"photo" ;
NSURL* returnURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: filename ofType:@"jpg" ]] ;
return returnURL ;
}
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return [documents count];
}
-(id)previewController:(QLPreviewController*)控制器PreviewWitematindex:(NSInteger)索引
{
NSString*filename=[documents objectAtIndex:index];/@“photo”;
NSURL*returnURL=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:文件名类型:@“jpg”];
返回URL;
}
-(NSInteger)PreviewWitemsInPreviewController的编号:(QLPreviewController*)控制器
{
返回[文件计数];
}
显示错误。
QLPreviewController是一个UIViewController,这意味着您基本上有两种显示方式: