Answer the question
In order to leave comments, you need to log in
How to pass data to a custom UITableViewCell before it is built?
I need to pass data to a cell when it is created in the tableView.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? LessonTableViewCell
// Внутри класса LessonTableViewCell ячейка заполняет саму себя переданными ей данными
/*код*/
}
Answer the question
In order to leave comments, you need to log in
An example from my project. ( I don’t provide the code in text, a terrible editor. )
In the delegate:
internal override func collectionView(
_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: CategoriesCollectionViewCell.reuseIdentifier,
for: indexPath
) as! CategoriesCollectionViewCell
let randomIndex = indexPath.item % CategoriesPlaceholder.images.count
cell.configure(
withImage: UIImage(named: CategoriesPlaceholder.images[randomIndex])!,
andTitle: CategoriesPlaceholder.titles[randomIndex]
)
return cell
}
internal final class CategoriesCollectionViewCell: UICollectionViewCell {
// =====================================
// MARK: - Configure
// =====================================
internal func configure(withImage image: UIImage?, andTitle title: String) {
illustrationCircle.image = image
self.title.text = title
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question