【发布时间】:2017-08-04 07:36:04
【问题描述】:
我有一个包含 2 个部分的 UITableView。在第一部分中,我不希望我创建的 UIView 出现在左侧。它在最初加载时工作正常,但当它离开屏幕并重新打开时,它会重新出现。
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 不断重新出现在我的单元格上。
标签: ios iphone swift uitableview swift3