[英]UIDocumentInteractionController change title of presented view
我正在使用UIDocumentInteractionController
來顯示 PDF 文件。 我的文件使用對用戶不友好的編碼文件名存儲在文件系統中。 我確實可以訪問該文件的更友好名稱,但該文件未使用此名稱存儲(出於唯一性原因)。
當我將文檔加載到UIDocumentInteractionController
,視圖會在標題欄中顯示不友好的“真實”文件名。
有什么方法可以更改UIDocumentInteractionController
顯示的標題嗎?
UIDocumentInteractionController
有一個name
屬性,您可以將其設置為您的用戶友好名稱。 該名稱將用於所呈現文檔的標題欄中。
這是 Xamarin (C#) 代碼,但我希望它有幫助
public class PreviewFile : IPreviewFile
{
public PreviewFile()
{
}
public void Preview(string file, string title)
{
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
bool isUrl = file.StartsWith("file:", StringComparison.OrdinalIgnoreCase);
var url = isUrl ? new NSUrl(file) : NSUrl.FromFilename(file);
var controller = UIDocumentInteractionController.FromUrl(url);
controller.Delegate = new MyInteractionDelegate(vc);
controller.Name = title;
controller.PresentPreview(true);
}
}
public class MyInteractionDelegate : UIDocumentInteractionControllerDelegate
{
UIViewController parent;
public MyInteractionDelegate(UIViewController controller)
{
parent = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return parent;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.