Objective c QLViewController仅显示单个文件

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

我正在使用QLPreviewController显示一组文件。然而,它只显示第一个,而我似乎无法滑动或做任何事情来显示第二个。我做错了什么?我必须手动设置吗?如果是的话,我该怎么做呢

这是来自我的AppDelegate.m:

- (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,这意味着您基本上有两种显示方式:

  • 将其推入UINavigationController
  • 以模式显示它(这可以在使用或不使用UINavigationController的情况下完成-取决于您是否需要导航栏)
  • 如果您选择选项2,您将获得“免费”导航箭头以在项目之间切换。 对于选项1,您需要自己创建箭头

    以下内容摘自文件:

    如果列表中有多个项目,则以模态方式呈现(即 is(全屏)控制器显示导航箭头,让用户 在项目之间切换。要快速查看预览,请按下控制器 使用导航控制器,可以在中提供按钮 用于在导航列表中移动的导航栏