我有4個subviews
在我cell
,imageView
照片始終顯示在每個cell
的imageview
使用圖標會一直顯示在顯示細胞不顯示的子視圖迅速
label
的遞減label
似乎只是有時
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = ""
if cell.contentView.viewWithTag(1000) == nil {
let name = UILabel(frame: CGRect(x: cell.frame.origin.x + cell.frame.width/3.3, y: cell.frame.origin.y + cell.frame.height/4, width: 200, height: cell.frame.height/5))
name.textAlignment = NSTextAlignment.Left
name.text = lines[indexPath.row].name
name.font = UIFont(name: "OpenSans-Bold", size: cell.frame.height/6)
name.textColor = UIColor(red: 247/255.0, green: 215/255.0, blue: 129/255.0, alpha: 1)
name.tag = 1000
cell.contentView.addSubview(name)
}
let name = cell.contentView.viewWithTag(1000)
if cell.contentView.viewWithTag(1001) == nil {
let desc = UILabel(frame: CGRect(x: cell.frame.origin.x + cell.frame.width/3.3, y: cell.frame.origin.y + cell.frame.height/4 + name!.frame.height, width: cell.frame.width/2, height: 0))
desc.textAlignment = NSTextAlignment.Left
if let age = lines[indexPath.row].age{
desc.text = String(age) + NSLocalizedString("radarTable.age", comment: "age")
print(lines[indexPath.row].isMale)
if let city = lines[indexPath.row].residence{
desc.text = desc.text! + DataService.instance.getResidenceMutation(city, sender: self)
}
}
desc.font = UIFont(name: "OpenSans", size: cell.frame.height/9)
desc.textColor = UIColor.whiteColor()
desc.numberOfLines = 2
desc.lineBreakMode = NSLineBreakMode.ByWordWrapping
desc.sizeToFit()
cell.contentView.addSubview(desc)
}
if cell.contentView.viewWithTag(1002) == nil{
let photo = UIImageView(frame: CGRect(x: 0, y: 0, width: cell.frame.height/1.6, height: cell.frame.height/1.6))
photo.image = lines[indexPath.row].photo
photo.center = CGPoint(x: (cell.frame.height/2), y: (cell.frame.height/2))
photo.contentMode = UIViewContentMode.ScaleAspectFill
photo.clipsToBounds=true
photo.layer.cornerRadius = photo.frame.height/2
photo.tag = 1002
cell.contentView.addSubview(photo)
}
if cell.contentView.viewWithTag(1003) == nil {
let image = UIImage(named: "profileIcon")
let backgroundView = UIImageView(frame: CGRect(x: cell.frame.origin.x + cell.frame.width/3.3 - cell.frame.height/7,y: cell.frame.origin.y + cell.frame.height/4 + cell.frame.height/25, width: cell.frame.height/10, height: cell.frame.height/10))
backgroundView.image = image
backgroundView.tag = 1003
backgroundView.center = (name?.center)!
backgroundView.frame.origin.x = cell.frame.origin.x + cell.frame.width/3.3 - cell.frame.height/7
cell.contentView.addSubview(backgroundView)
}
return cell
}
這就是它的樣子 tableview
我明白了,我試過,但行爲還是一樣,我試圖打印willDisplayCell標籤文本,它看起來像標籤存在幷包含正確的文本,但它不顯示 –
嘗試使使用bringSubviewToFront方法標籤到前面 – Meet
是這樣的嗎?其他{ let name = cell.contentView.viewWithTag(1000)as!的UILabel cell.contentView.bringSubviewToFront(名稱) } –