gpt4 book ai didi

iphone - 如何将按钮添加到 QLPreviewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:31 27 4
gpt4 key购买 nike

是否可以将新按钮添加到工具栏或 QLpreviewController 右上角的 actionButton 中?

如果是,我该如何编写代码?

最佳答案

尽管 QLPreviewControllerUIViewController 的子类,但更改导航项没有任何效果。例如,这段代码理论上应该可以工作,但实际上并没有:

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.navigationItem.rightBarButtonItem =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self action:@selector(share)]

但是,您可以将工具栏添加到 QLPreviewController。首先设置工具栏以在加载 View 时显示:

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.toolbarHidden = YES;
}

接下来,从 QLPreviewController 委托(delegate)中设置您的 toolbarItems:

- (id)previewController:(QLPreviewController *)previewController 
previewItemAtIndex:(NSInteger)idx {

UIBarButtonItem *testButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Test"
style:UIBarButtonItemStylePlain
target:self
action:@selector(testButtonTapped:)];

NSArray *myToolbarItems = [NSArray arrayWithObjects:testButtonItem, nil];
previewController.toolbarItems = myToolbarItems;
[testButtonItem release];
}

关于iphone - 如何将按钮添加到 QLPreviewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490433/

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