У меня есть 6 пользовательских ячеек в табличном представлении.В том, что у 3 из них есть представление изображения, я добавил tapGesture в imageView и включил взаимодействие с пользователем imageView, все еще не работающее.Я также пытался добавить tapGesture в основной шаг в классе ячеек табличного представления, но безрезультатно, я даже пытался добавить жест в ячейку для метода IndexPath, но не сработал, как решить эту проблему?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellArr = sections[indexPath.section].cell
//Loading cell based on array details
switch cellArr[0] {
case is InsuranceDetails:
let insuranceCell = tableView.dequeueReusableCell(withIdentifier: "insuranceCell") as! InsuranceCell
insuranceCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
case is Pollution:
let pollutionCell = tableView.dequeueReusableCell(withIdentifier: "pollutionCell") as! PollutionCell
pollutionCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
return pollutionCell
case is Servicing:
let servicingCell = tableView.dequeueReusableCell(withIdentifier: "servicingCell") as! ServicingCell
servicingCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
return servicingCell
case is ChallanPaid:
let challanPaidCell = tableView.dequeueReusableCell(withIdentifier: "challanPaidCell") as! ChallanPaidCell
challanPaidCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
return challanPaidCell
case is InsuranceClaims:
let insuranceClaimCell = tableView.dequeueReusableCell(withIdentifier: "insuranceClaimCell") as! InsuranceClaimCell
insuranceClaimCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
return insuranceClaimCell
case is FuelRefills:
let fuelRefillCell = tableView.dequeueReusableCell(withIdentifier: "fuelRefillCell") as! FuelRefillCell
fuelRefillCell.setup(object: cellArr[indexPath.row], in: tableView, at: indexPath)
return fuelRefillCell
default:
return UITableViewCell()
}
}
одинмоего класса ячеек таблицы
class InsuranceCell: UITableViewCell {
@IBOutlet weak var insurancePhoto: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func setup(object: NSManagedObject, in table: UITableView, at indexPath: IndexPath) {
guard let arr = object as? InsuranceDetails else {return}
let tapgesture = UITapGestureRecognizer(target: self, action: #selector(imageTapped))
insurancePhoto.isUserInteractionEnabled = true
tapgesture.numberOfTapsRequired = 1
insurancePhoto.isUserInteractionEnabled = true
insurancePhoto.addGestureRecognizer(tapgesture)
// Do time consuming stuff in the background
DispatchQueue.global(qos: .userInitiated).async {
let imageData = arr.insurancePhoto ?? Data()
let image = UIImage(data: imageData)
let compimage = image?.resized(withPercentage: 0.5)
// Always back to the main thread/queue for UI updates
DispatchQueue.main.async {
guard let cell = table.cellForRow(at: indexPath) as? InsuranceCell else { return }
cell.insurancePhoto.image = compimage
}
}
}
}