2013年8月27日 星期二

UITableViewCell deselect 取消選取


有沒有遇到過UITableViewCell 按下去之後就一直有呈現選擇的狀態

只在didSelectRowAtIndexPath加上

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{  

    // Your code here ...  
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

 }


就可以了喔 

animated YES的話會有藍色選取被漸淡的動畫






另外一種方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleBlue(By Default)
    cell.selectionStyle = UITableViewCellSelectionStyleGray;

}

UITableViewCellSelectionStyleNone就是不給選UITableViewCellSelectionStyleBlue 就是預設藍
UITableViewCellSelectionStyleGray 灰色



試試看吧!




1 則留言:

  1. 謝謝你的分享
    正好解決了有點困擾我的問題
    通常選cell後的行為會離開原先的viewController
    但我在撰寫的程式正好有選了卻留在原地的情形
    讓我的cell一直藍藍的有點不舒服XD

    回覆刪除