遇到的bug如上圖典鸡,經(jīng)測試只在iOS11上才有這樣的問題潮针,排除了干擾因素,最終把bug的原因確定了雌澄。
上面的代碼是運用
Method Swizzling
替換系統(tǒng)默認方法來防止字典賦值為空時崩潰斋泄,注釋了之后tableView側(cè)滑的bug就好了。至于為什么iOS11才會出現(xiàn)個人猜想是因為蘋果在iOS11上重新實現(xiàn)了UITableView的側(cè)滑效果镐牺,提供了新的方法炫掐。新的方法提供了:左側(cè)按鈕自定義、右側(cè)按鈕自定義睬涧、自定義圖片募胃、背景顏色。
// Swipe actions
// These methods supersede -editActionsForRowAtIndexPath: if implemented
// return nil to get the default swipe actions
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
正好新方法的實現(xiàn)用到了NSMutableDictionary而且需要傳入空值畦浓,被我們自己寫的方法攔截了才導(dǎo)致的痹束。看來runtime大法還是得謹慎使用哇Q惹搿5凰弧!