周一早上一開會(huì),就聽到一個(gè)噩耗,上線已久的app有一個(gè)必現(xiàn)的crash的bug,心情瞬間有些涼。
直接上問(wèn)題吧
有一個(gè)用tableview做的一個(gè)填寫表單頁(yè)面,只要在填寫時(shí),切換到手寫輸入法,手寫之后就會(huì)crash,然后錯(cuò)誤提示:[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance,之前從來(lái)沒遇到過(guò)這種錯(cuò)誤,一直不知所措。只好求助萬(wàn)能的谷歌百度,原來(lái)是手勢(shì)沖突原因。
由于之前開發(fā)的時(shí)候,為了讓填寫表單是彈出的鍵盤能點(diǎn)擊空白處收回鍵盤,就給scrollview寫了一個(gè)分類,重寫了三個(gè)方法。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}
手寫輸入法和這個(gè)分類處理手勢(shì)沖突導(dǎo)致app crash了。找到問(wèn)題就好辦了,最后放棄了這個(gè)分類,解決手寫輸入crash的bug,但是點(diǎn)擊tableview空白收回鍵盤的功能也就失效了。最后只有往tableview上加一個(gè)tap手勢(shì),來(lái)收回鍵盤。鍵盤是回收了,但是tableview上一些cell不能點(diǎn)擊跳轉(zhuǎn)了,又是手勢(shì)沖突。還好添加的手勢(shì)有一個(gè)cancelsTouchesInView屬性,文檔解釋:A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.這個(gè)布爾屬性默認(rèn)是YES,就是會(huì)取消手勢(shì)的傳遞到視圖,所以在給tableview添加手勢(shì)的時(shí)候,將次屬性設(shè)置為NO,這樣手勢(shì)可以傳遞到tableview上,從而可以響應(yīng)Cell的選擇事件。