gpt4 book ai didi

objective-c - QLPreviewController 仅显示单个文件

转载 作者:行者123 更新时间:2023-11-29 04:33:22 26 4
gpt4 key购买 nike

我正在使用 QLPreviewController 来显示一组文件。但是,它只显示第一个,我似乎无法滑动或执行任何操作来显示第二个。我究竟做错了什么?我必须手动设置吗?如果是这样 - 我将如何去做?

这是来 self 的 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];
}

最佳答案

您的显示方式有误。QLPreviewController 是一个 UIViewController,这意味着您基本上有两种显示它的方式:

  1. 将其插入您的 UINavigationController。
  2. 以模态方式显示它(可以使用或不使用 UINavigationController 来完成 - 取决于您是否需要导航栏)。

如果您选择选项 2,您将获得“免费”导航箭头以在项目之间切换。对于选项 1,您需要自己创建箭头。

以下内容摘自 QLPreviewController文档:

If there is more than one item in the list, a modally-presented (that is, full-screen) controller displays navigation arrows to let the user switch among the items. For a Quick Look preview controller pushed using a navigation controller, you can provide buttons in the navigation bar for moving through the navigation list.

关于objective-c - QLPreviewController 仅显示单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11394021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com