gpt4 book ai didi

iPhone UIDocumentInteractionController PresentOpenInMenuFromRect 取消按钮没有响应

转载 作者:行者123 更新时间:2023-12-03 20:23:12 24 4
gpt4 key购买 nike

在 iPhone4 和 iPad2(均在 iOS 4.3.5 中运行)中执行“presentOpenInMenuFromRect”时,我观察到不同的行为。在iPad2中,它显示一个下拉列表,其中包含可以打开特定文件的所有应用程序,并且工作正常;然而,在iPhone4中,它还显示一个下拉列表(并且也可以正常工作),但在下拉列表的末尾有一个“取消”按钮,该按钮似乎处于非事件状态。

在iPad2中不会出现这个问题,因为“取消”按钮没有出现,只出现下拉列表,当我点击与下拉列表不同的另一个区域时,该列表被关闭;这是期望的行为。

我所说的“取消”按钮在 iPhone/iPhone4 中似乎处于非事件状态是指:当我触摸它时,什么也没有发生!好吧,更具体地说,如果我在短时间内或短时间内多次触摸它,那么,“取消”按钮似乎会响应(它的颜色从灰色变为蓝色),然后下拉列表会晚于早一些确实关闭了;这是期望的行为。

我按以下方式使用“presentOpenInMenuFromRect”:我实现了一个“保存”按钮,默认情况下该按钮是隐藏的;但是,在方法“-(void)webViewDidFinishLoad:(UIWebView *)webView”中,我检测 URL 的“路径扩展名”,如果它具有“.pdf”扩展名,则显示“保存”按钮;即:

-  (void)webViewDidFinishLoad:(UIWebView *)webView
{
if ([[[myWebViewOL.request.URL.absoluteString pathExtension] lowercaseString] isEqualToString:@"pdf"])
{
saveFile0L.hidden = NO;
}
}

与“保存”按钮(saveFile0L)相关的“操作”是以下方法“saveFile”:

[saveFile0L addTarget:self action:@selector(saveFile) forControlEvents:UIControlEventTouchUpInside];

其中“saveFile”具有以下代码:

- (void) saveFile
{
//Do not worry about "FileManager" is only a singleton class
//which I have defined in order to implement some common methods
//and one of them is "saveFile:(UIWebView*) withUIView:(UIView*)
[[FileManager sharedInstance] saveFile:myWebView withUIView:self.view];
}

“saveFile:(UIWebView*)myWebView withUIView:(UIView*)self.view”具有以下代码:

- (void) saveFile:(UIWebView*)webView withUIView:(UIView*)view
{
NSString* fileName = [[NSFileManager defaultManager] displayNameAtPath:webView.request.URL.absoluteString];
NSURL* fileurl = [NSURL URLWithString:webView.request.URL.absoluteString];
NSData* data = [NSData dataWithContentsOfURL:fileurl];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docsDirectory = [paths objectAtIndex:0];
NSString* filePath = [docsDirectory stringByAppendingPathComponent:fileName];
[data writeToFile:filePath atomically:YES];
NSURL* url = [NSURL fileURLWithPath:filePath];
//UIDocInteractionController API gets the list of devices that support the file type
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
[docController retain];
//Note:[docController presentOpenInMenuFromRect:CGRectZero inView:view animated:YES]
//presents a drop down list of the apps that support the file type,
//clicking on an item in the list will open that app while passing in the file.
//Note: [[UIApplication sharedApplication] canOpenURL:fileurl]
//will return YES if there is an app that can handle the specific file
BOOL isValid = ([[UIApplication sharedApplication] canOpenURL:fileurl] &&
[docController presentOpenInMenuFromRect:CGRectZero inView:view animated:YES]);
if (!isValid)
{
[self showAlertSaveFileError:fileName];
}
}

目前,我不知道如何使“取消”按钮正常工作,该按钮仅出现在iPhone(而不是iPad)中的下拉列表末尾。

提前致谢,

最佳答案

BOOL isValid = ([[UIApplication sharedApplication] canOpenURL:fileurl] &&
[docController presentOpenInMenuFromRect:CGRectZero inView:view animated:YES]);

尝试将 view inView:view 更改为 inView:self.view.window

关于iPhone UIDocumentInteractionController PresentOpenInMenuFromRect 取消按钮没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7015153/

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