背景:UITableView上显示了十几个UITextField控件用来设置参数。来回切获取焦点时,概率性崩溃。
崩溃日志:
frame #1: 0x3012cce0 UIKit`-[UIResponder(Static) _setFirstResponder:] + 44
frame #2: 0x3012cce0 UIKit`-[UIResponder(Static) _setFirstResponder:] + 44
frame #3: 0x3012cce0 UIKit`-[UIResponder(Static) _setFirstResponder:] + 44
frame #4: 0x30118732 UIKit`-[UIResponder resignFirstResponder] + 250
frame #5: 0x3027bb68 UIKit`-[UIWebDocumentView resignFirstResponder] + 232
frame #6: 0x3027ba7c UIKit`-[UIWebBrowserView resignFirstResponder] + 124
frame #7: 0x30072504 UIKit`-[UIView(Hierarchy) _willMoveToWindow:] + 660
解决方案:
endEditing:YES
代替
resignFirstResponder
From Apple Doc:
- (BOOL)endEditing:(BOOL)force Description Causes the view (or one of its embedded text fields) to resign the first responder status. This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign. Parameters
force
Specify YES to force the first responder to resign, regardless of whether it wants to do so. Returns YES if the view resigned the first responder status or NO if it did not.