2016-07-08 10 views
0

DocumentPickerが完全に機能するようになっています。今はビューコントローラを提示しますが、結果を待つ方法や結果を得る方法がわかりません。XamarinフォームでのUIDocumentPickerViewControllerの選択

すぐにvoid documentPicker(UIDocumentPickerViewController controller, didPickDocumentAtUrl...メソッドを書きます。終了したらそこに行きます。

しかし、Xamarinでは、単純ではありません。私はそれを私のAppDelegate.csクラスだけでなく、私のMain.csクラスと同様に呼び出すクラスから、そのメソッドを書いています。私が間違って書いていない限り、それはうまくいかないようです。

私は何を持っていることは

public async Task<string> pickResume() 
{ 
    string path = string.Empty; 

    var controller = new UIViewController(); 
    var docVC = new UIDocumentPickerViewController(new string[] { "org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc" }, UIDocumentPickerMode.Import); 
    UIViewController topController = getTopViewController(); 
    topController.PresentViewController(docVC, true, null); 

    return path; 
} 

void documentPicker(UIDocumentPickerViewController controller, NSUrl didPickDocumentAtURL) 
{ 
    Console.WriteLine("done"); 
} 

getTopViewController()

答えて

0

はそれを考え出した私はDocumentPickerを提示することができるように、トップビューコントローラを取得するだけのヘルパーメソッドです....これで、それはたくさんです私はそれを作ることよりも簡単だった。

UIDocumentPickerViewControllerには2つのEventHandlers,DidPickDocumentおよびWasCancelledがあります。そのため、2つの異なる方法に割り当てただけです。

public async Task<string> pickResume() 
{ 
    string path = string.Empty; 
    var controller = new UIViewController(); 

    var docVC = new UIDocumentPickerViewController(new string[] { "org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc" }, UIDocumentPickerMode.Import); 
    docVC.DidPickDocument += DocVC_DidPickDocument; 
    docVC.WasCancelled += DocVC_WasCancelled; 

    UIViewController topController = getTopViewController(); 
    topController.PresentViewController(docVC, true, null); 

    return await GetDocPath(new CancellationTokenSource()); 
} 

private void DocVC_WasCancelled(object sender, EventArgs e) 
{ 
    //Handle being cancelled 
} 

private void DocVC_DidPickDocument(object sender, UIDocumentPickedEventArgs e) 
{ 
    //Handle document selection 
} 
関連する問題