When the app first build, it seem like working just fine, please see pic where each pics is one cell in side the table view
. (I am working to place them properly)
The problem that I am facing is that: once I scroll down and scroll up again. Each cell data got massed up. Please see pics. Which I still have no idea what is wrong in my coder after hours searching online and decoding. please point out what I am missing. I have attached my code.
I am using the tutorial code from Ray Wenderlich and adding the codes below in the
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
method Yes I am doing it each word as UIBotton to trigger an action.
Adding
"cell.contentView.subviews.filter { $0 is UILabel }.forEach { $0.removeFromSuperview() }"
didn't solve the issue. please give me a completed example?(working one) Thank you.
let wholeSentense = artist.bio
let whoeSentenseArray = wholeSentense.components(separatedBy: " ")
var xPos = CGFloat(0)
for element in whoeSentenseArray {
var button = UIButton()
button.setTitle(element, for: UIControlState.normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
let buttonTitleSize = (element as NSString).size(attributes: [NSFontAttributeName : UIFont.boldSystemFont(ofSize: 15 + 1)])
button.frame.size.height = buttonTitleSize.height * 1.5
button.frame.size.width = buttonTitleSize.width
button.frame.origin.x += xPos
xPos = xPos + buttonTitleSize.width + 10
button.setTitleColor(UIColor.black, for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: UIControlEvents.touchDown)
cell.addSubview(button)
}
return cell
}
func buttonAction(sender: UIButton!) {
print("\n\n Title \(String(describing: sender.titleLabel?.text)) TagNum \(sender.tag)")
// print("Button tapped")
}