【问题标题】:tableview bounces on updating of cell on button click表格视图在按钮单击时更新单元格时反弹
【发布时间】:2018-01-17 08:12:50
【问题描述】:

Table bounce on updating of cell label number of lines.

我正在更新我的单元格标签编号行并且表格反弹。 我的代码如下。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    tableView.deselectRow(at: indexPath, animated: false)        
    let cell = tableView.cellForRow(at: indexPath) as! VendorTableViewCell
     tableView.beginUpdates()
    cell.cell_description.numberOfLines = (cell.cell_description.numberOfLines == 0) ? 2 : 0
        self.cellStates?[indexPath.row - 1] = (cell.cell_description.numberOfLines == 0) ? .expanded: .collapsed
    defer { 
           tableView.endUpdates() 
          }

}

【问题讨论】:

    标签: ios iphone swift uitableview ios11


    【解决方案1】:

    试试这个

     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        tableView.deselectRow(at: indexPath, animated: false)        
        let cell = tableView.cellForRow(at: indexPath) as! VendorTableViewCell 
        self.cellStates?[indexPath.row - 1] = (cell.cell_description.numberOfLines == 0) ? .expanded: .collapsed
        self.tableView.reloadData()
    
    }
    

    并将其放入 cellForRow

        cell.cell_description.numberOfLines = (cell.cell_description.numberOfLines == 0) ? 2 : 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 2012-11-18
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多