从生成已删除的单元格中停止表

时间:2015-03-16 03:21:29

标签: swift uitableview cell generated

这是我用来在RSS提要阅读器中生成常规表格单元格的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Function adds the title to each cell
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
    let item = feedItems[indexPath.row] as MWFeedItem

    cell.textLabel?.text = item.title
    return cell

}

我想在上面的函数中添加一个if语句,在用户已经删除了feed的情况下,该语句将停止生成表格单元格。我知道如何检查它是否已被删除(在if之后括号内的内容),但不是我将放在实际的if语句中。

if(/*table cell has been deleted*/)
{
/*code that stops this feed from being regenerated*/
}

1 个答案:

答案 0 :(得分:0)

执行此操作的方法是实际删除或删除feedItems中的项目,然后使用tableView重新加载tableView.reloadData()。然后,这将为tableView提供正确数量的元素,仅绘制feedItems中包含的所有元素。

希望这有帮助。