Why does UITableViewCell remain highlighted?

前端 未结 18 1262
余生分开走
余生分开走 2020-12-12 12:45

What would cause a table view cell to remain highlighted after being touched? I click the cell and can see it stays highlighted as a detail view is pushed. Once the detail

18条回答
  •  攒了一身酷
    2020-12-12 13:10

    if the cell is remaining highlighted after touching it, you can call UITabelView method,

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

    `[tableView deselectRowAtIndexPath:indexPath animated:YES];`   
    

    }

    Or, you can use the following method and modify it according to your requirements,

    // MARK: UITableViewDelegate

    func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) {
      if let cell = tableView.cellForRowAtIndexPath(indexPath) {
         cell.backgroundColor = UIColor.greenColor()
      }
    }
    
    func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) {
      if let cell = tableView.cellForRowAtIndexPath(indexPath) {
         cell.backgroundColor = UIColor.blackColor()
      }
    } 
    

提交回复
热议问题