I currently have a UITableView in which each cell contains a list of users. I currently have it setup using a UITextView and line break after each name. I then set the cell height accordingly to how many people are in the group.This is working great but now I want to add profile pictures by each use. Here are two possible solutions I have come up with.
- A tableview inside each table view cell
- Using a method like this in order to add the image in as text and keep the current textview. I believe this would be the better/ more efficient option.
Which method of these two or other option would be the right way/ or most efficient way of going about doing this.
UPDATE : I am trying to implement a solution from below here is what I have tried but I am seeing nothing when running
ADDING STACK VIEW IN STORYBOARD
CREATING USER VIEW CLASS
import UIKit
@available(iOS 9.0, *)
class UserView: UIStackView {
var name: String?
var image: UIImage? // OR var imageName: String?
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
private func setup() {
axis = .vertical
let imageView = UIImageView(image: image)
let nameLabel = UILabel()
nameLabel.text = name
addArrangedSubview(imageView)
addArrangedSubview(nameLabel)
}
}
CODE IN CELL FOR ROW AT INDEX PATH
cell.mainStackView.frame = CGRect(x: 0, y: 0, width: cell.cellColor.frame.width, height: cell.cellColor.frame.height)
for i in 0..<joinedArray.count {
let user = UserView()
user.name = joinedArray[i]
cell.mainStackView.addArrangedSubview(user)
}