UIDocumentBrowserViewController不调用localizedName或不遵守shouldShowFileExtensions。

huangapple go评论59阅读模式
英文:

UIDocumentBrowserViewController doesn't call localizedName or honor shouldShowFileExtensions

问题

我使用的是在macOS Ventura 13.2上的Xcode 14.2,正在开发一个最初是通过Xcode的模板创建的iOS应用,通过New Project > iOS > Document App创建。我使用Objective-C而不是Swift。我正在模拟器的"iPad Pro (12.9 in) 6th Generation - iOS 16.2"模块中进行测试。

模板创建了一个UIDocumentBrowserViewController子类和一个UIDocument子类,我一直在填写这两个类。

我遇到了两个问题。

首先,文档浏览器忽略了它自己的shouldShowFileExtensions属性。我已将其设置为NO,并在运行时再次检查它仍然为NO;但浏览器视图仍然显示文件名扩展名。

其次,我希望浏览器显示UIDocument.localizedName字符串而不是文件名。这是UIDocument的一个只读属性,据说可以通过子类覆盖以返回任何您想要的字符串。我的UIDocument子类的覆盖从未被调用。

覆盖看起来像这样:

- (NSString*)localizedName
{
    return [self projectName];
}

我没有对我的子类做任何奇怪的事情;我已尽力遵循苹果的指南和文档。我的应用程序将创建后在浏览器中显示的文档,可以再次打开并显示,所以基本功能是正常的;但我无法控制浏览器中文档的显示名称。

我做错了什么?提前感谢任何帮助。

英文:

I am using Xcode 14.2 on macOS Ventura 13.2, working on an iOS app initially created from Xcode's template via New Project > iOS > Document App. I am using Objective-C, not Swift. I am testing in the simulator's "iPad Pro (12.9 in) 6th Generation - iOS 16.2" module.

The template created a UIDocumentBrowserViewController subclass and a UIDocument subclass, which I've been filling in.

I have two problems.

First, the document browser is ignoring its own shouldShowFileExtensions property. I have it set to NO, and I have checked that it is still NO later during runtime; but the browser view still displays filename extensions.

Second, I'd really rather the browser displays the UIDocument.localizedName string instead of the filename. This is a read-only property of UIDocument which is supposedly overridable by the subclass to return whatever string you'd like. My UIDocument subclass's override is never being called.

The override looks like this:

- (NSString*)localizedName
{
    return [self projectName];
}

I am not doing anything weird with my subclasses; I've done my best to follow Apple's guidelines and documentation meticulously. My app will create documents that later appear in the browser, and which can be opened again and displayed, so the basics are working; but I have no control over the display name of the documents in the browser.

What am I doing wrong? Thanks in advance for any help.

答案1

得分: 0

localizedName 不会被文档浏览器使用,否则它将不得不为用户访问的目录中的每个文件创建一个 UIDocument!这将对性能产生巨大影响。如文档中所解释,LocalizedName 仅用于在打开文档后在错误消息和类似情况下显示文档的名称。

英文:

localizedName is not used by the document browser, or it would have to create a UIDocument for every file in the directories the user visits! This would have a huge performance impact. LocalizedName is only used, as explained in the documentation, to display the document’s name after it is open in error messages and the like.

huangapple
  • 本文由 发表于 2023年2月14日 05:39:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441436.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定