我有以下流程:resignFirstResponder與後續處理的問題(鍵盤解僱iPhone 5的阻塞或崩潰)
Input in Textfield -> (Return key of TextField pressed: resignFirstResponder, IBAction of Button called) -> IBAction of Button: perform an intensive operation
的問題是,鍵盤與resignFirstResponder
解僱前的密集操作開始。作爲建議的其他職位(如https://stackoverflow.com/a/3452767/1685971)我試圖用:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self performSelector:@selector(ibActionMethod:) withObject:sender afterDelay:someTime];
return YES;
}
這工作正常,在模擬器或iPhone 4,但導致對iPhone 5(我不明白運行崩潰,因爲我沒有使用performSelectorInBackground:withObject:
):
void _WebThreadLockFromAnyThread(bool): Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
bool _WebTryThreadLock(bool): Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
我嘗試另一種選擇是等待resignFirstResponder在主線程與
[textField performSelectorOnMainThread:@selector(resignFirstResponder) withObject:nil waitUntilDone:YES];
但有了這個鍵盤是STIL我不立即解散(可能是因爲該方法只等待選擇器resignFirstResponder
的返回,而不是等待鍵盤動畫的結束。
有沒有解決這個問題的方法?
我不認爲你的意思是通過發件人? – Bushbert 2013-02-19 08:52:48
@Jonathan:對不起,你的意思是?發件人僅傳遞給IBAction - 但這不是問題。 – FrankZp 2013-02-19 09:24:17