Нажмите Жест не работает для imageView в ячейке просмотра таблицы - PullRequest
0 голосов
/ 27 сентября 2019

У меня есть 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


        }

    }
}

}

1 Ответ

0 голосов
/ 27 сентября 2019
 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)
        let tapgesture = UITapGestureRecognizer(target: self, action: #selector(imageTapped))

        insuranceCell.tapgesture.numberOfTapsRequired = 1
        insuranceCell.insurancePhoto.isUserInteractionEnabled = true
        insuranceCell.insurancePhoto.addGestureRecognizer(tapgesture)
        return insuranceCell
    }
}

@IBAction func imageTapped(gesture: UITapGestureRecognizer) {

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...