У меня есть это для моего представления таблицы
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CurrentItemsCell {
cell.isUserInteractionEnabled = true
let responseItems = currentItemsArray[indexPath.row]
cell.configureCell(currentItem: responseItems)
cell.setNeedsLayout()
return cell
} else {
return CurrentItemsCell()
}
}
Вот мой материал ячейки.
class CurrentItemsCell: UITableViewCell {
...
weak var mDelegate:MyProtocolImage?
...
}
@IBAction func showImages(_ sender: Any) {
guard let indexPath = indexPath else { return }
mDelegate?.sendIndexPathBack(row: indexPath.row)
print("FROM THE CELL CLASS")
}
protocol MyProtocolImage: class {
func sendIndexPathBack(row: Int)
}
Внутри UITableView я пытался добавить cell.mDelagate = self, но естьошибка.
Cannot assign value of type 'ItemResultsViewController' to type 'MyProtocolImage?'
Что теперь, если я сделаю cell.mDelegate = self as! MyProtocolImage
, синтаксис в порядке, но приложение вылетает.
По сути, у меня есть кнопка внутри каждой ячейки, мне нужно получить indexRow ячейки, чтобы я мог получить itemId любой кнопки элемента, которая была нажата. Затем я должен отправить itemId новому ViewController (модальному) с Seque.
Любая помощь будет потрясающей