2016-12-27 96 views
-1

我希望当我触摸按钮时,它会导致标签展开。在TableView中更新一个单元格

我试着用numberOfLines和它的作品,但滚动表视图,标签和其他细胞的时候也得到扩大:(

我怎么能够只更新一个细胞?

我使用table.beginUpdates但它不是答案,因为向下滚动时,其他单元也将改变

这是我的代码,例如:

extension ViewController: UITableViewDataSource { 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 10 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(indexPath: indexPath) as  FoodTableViewCell 
     cell.title.text = "adshflakdsjfhalkdsjfhladksjfhadlkfhadlkfhaldkfhdlkfhadjfhaldfhaldfhaldskfhdslkhflakdshfladksfhladfhladfhal" 
     cell.delegate = self 
     return cell 
    } 
} 

extension ViewController: CellDelegate { 

    func action(cell: FoodTableViewCell) { 
     cell.title.numberOfLines = 0 
    } 
} 

我想这一点:

enter image description here

+0

您想要触摸的按钮是在单元格内吗?或者别的地方? – Jeet

+0

它正在发生,因为您正在重新使用该单元格。 –

+0

是的。这是正确的@Jeet –

回答

0

我解决。我在模型中设置了一个标志并检查它

相关问题