實現了 tableView:didDeselectRowAtIndexPath:,第一次點擊 Cell 無反應,點擊第二個 Cell 時第一個才觸發邏輯。
方法名搞錯了:
didSelectRowAtIndexPath:**選中**行時調用(點擊即觸發)。didDeselectRowAtIndexPath:**取消選中**行時調用(需先有選中行,再點擊其他行才觸發前一行的取消選中)。第一次點擊無「已選中行」,故 didDeselect 不觸發;點第二行時,第一行取消選中 → 觸發 didDeselect,看起來像「延遲一拍」。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES]; // 取消高亮
// 你的跳轉邏輯...
switch (indexPath.row) {
case 0: ...
case 1: ...
}
}
deselectRowAtIndexPath:animated:**,否則 Cell 長期高亮體驗極差。[self navigateToModuleAtIndex:indexPath.row];didDeselectRowAtIndexPath。**點擊 Cell 響應 = didSelectRowAtIndexPath**。didDeselect 是「失去焦點」回調。一字之差,行為天壤之別。新手必踩坑,記住即可。