2013-06-26 22 views
2

當用戶在觸摸鍵盤上按GO時,我正嘗試從iOS設備撥打我的web服務。我想要一個加載指示器在與web服務對話時顯示。如何異步設置委託類型UITextField.ShouldReturn?

我爲代表類型UITextFieldCondition使用lambda表達式。

LoginField.ShouldReturn = async textField => { 
     await LoginAsync(); 
     return textField.ResignFirstResponder(); 
    }; 

編譯器顯示我下面的錯誤:

LoginField.ShouldReturn = textField => { 
     Login(); 
     return textField.ResignFirstResponder(); 
    }; 

有沒有做這件事的辦法:如果我去做了同步

Cannot convert async lambda expression to delegate type `MonoTouch.UIKit.UITextFieldCondition'

代碼工作?

回答

1

基本上,沒有辦法做到這一點。 UITextFieldCondition的簽名表示您的代理人同步返回結果。

我認爲你需要改變你處理這個問題的方式。可能是這樣的:

LoginField.ShouldReturn = textField => 
{ 
    LoginAsync().ContinueWith(t => /* react to t.Result manually here */); 
    return false; 
};