1
我有一个数组类型的字符串数组,我在for循环内输出tableView
。我知道它在cellForRowAt indexPath
内部是一个不好的练习循环:function但我没有solution.My问题是我每次移动时我tableview
模拟器上,我插入更多的子视图上现有ones.it覆盖旧的,防止我使用当我删除细胞子视图时,Swift 3 UITableView细胞分离器消失
for view in cell.subviews {
view.removeFromSuperview()
}
,但它会删除我的细胞分隔符与我的大电池标签。我怎样才能删除单元格数据不是我的分隔符。
func tableView(_ tableView: UITableView, cellForRowAt indexPath:IndexPath) -> UITableViewCell {
var cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
//print(cell.subviews)
for view in cell.subviews {
view.removeFromSuperview()
}
for i in 0..<globalHeaderStructArray.count{
var newLabel = UILabel(frame: CGRect(x:xCoordination, y:10, width:Double(globalHeaderStructArray[i].width)!, height:30.0))
newLabel.font = UIFont(name: "Avenir", size: 17.0)
newLabel.textColor = UIColor.darkGray
newLabel.text = "\(globalDataArray[indexPath.row][i])"
var scrollview = UIScrollView(frame: cell.bounds)
scrollview.contentSize = CGSize(width:cell.bounds.width * 5, height:cell.bounds.height) // will be 5 times as wide as the cell
scrollview.isPagingEnabled = true
cell.contentView.addSubview(scrollview)
cell.addSubview(newLabel)
xCoordination += Double(globalHeaderStructArray[i].width)!
}
xCoordination = 0.0
return cell
}
如果我们不鼓励使用模糊标签,除非100%绝对必要(这对于传统架构问题来说极其罕见并且通常是错误的)。如果您需要参考,请使用指针..... – TheCodingArt