IOS 開發(fā)之實(shí)現(xiàn)取消tableView返回時(shí)cell選中的問題
在對表格UITableView操作時(shí),有時(shí)當(dāng)用戶選中表格行后,需要自動(dòng)取消選擇。實(shí)現(xiàn)這種效果,其原理是選中表格行時(shí),會(huì)調(diào)用 didSelectRowAtIndexPath方法,只要在這個(gè)方法中,調(diào)用performSelector執(zhí)行取消選中表格行的方法。
示例代碼如下:
- (void) unselectCurrentRow{ // Animate the deselection [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];} - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)newIndexPath{ // Any other table management you need ... // After one second, unselect the current row [self performSelector:@selector(unselectCurrentRow)withObject:nil afterDelay:1.0];}
在performSelector中還可以設(shè)定延遲時(shí)間。unselectCurrentRow方法中則完成取消表格行的選擇,并且實(shí)現(xiàn)了動(dòng)畫效果。
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選