我有一个UITableView包含2个部分。在第一部分中,我不想让我创建的UIView出现在左侧。它在最初加载时工作正常,但当它离开屏幕并再次返回时,它会再次出现。滚动关闭后再显示在UITableViewCell中查看
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier") as! ATableCell;
cell.delegate = self;
if (indexPath.section == 1)
{
// let height = cell.bounds.size.height;
let height = 100;
let turnsView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: height));
turnsView.backgroundColor = UIColor.purple;
cell.addSubview(turnsView);
}
else
{
let height = 100;
let turnsView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: height));
turnsView.backgroundColor = UIColor.clear;
cell.addSubview(turnsView);
}
// Configure the cell...
cell.backgroundColor = UIColor.clear;
cell.textLabel?.text = "texting";
cell.detailTextLabel?.text = "testing";
}
我不希望紫色视图出现在第一部分的任何一点。
为您的视图分配一个标记,并在创建它们之前使用if-let语句删除它们,如果它们已经存在于单元格中。我有一个类似的问题,当滚动开始时,我的uilabels会再次出现在我的单元格上。 – Rishabh