如何从didSelectRowAtindexPath:函数访问单元格imageView

时间:2019-04-03 05:38:10

标签: ios swift uitableview

我正在尝试为单元格中的UIImageView使用核心动画。我不确定如何访问单元格或UIImageView

我正在使用Swift 5。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! CountryListCell
        cell.accessoryType = .disclosureIndicator

        let str =  factsJsonList[indexPath.row].country
        let image =  UIImage(named: str)


        cell.flagImageView.image = image
        cell.flagNameLabel.text = str.uppercased()

        return cell
    }



    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


        let cell = [tableView.cellForRow(at: indexPath)]
        // TODO :core animate the image view

        let vc = CountryFactListVC()
        vc.country = factsJsonList[indexPath.row]
        navigationController?.pushViewController(vc, animated: true)
    }

2 个答案:

答案 0 :(得分:0)

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

//access the current cell

         guard let cell = tableView.cellForRow(at: indexPath) as? CountryListCell else{
    return 
    }
            // TODO :core animate the image view

            let vc = CountryFactListVC()
            vc.country = factsJsonList[indexPath.row]
            navigationController?.pushViewController(vc, animated: true)
        }

答案 1 :(得分:0)

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

//access the current cell

     guard let cell = tableView.cellForRow(at: indexPath) as? CountryListCell 
     else{
       return 
     }
        // TODO :core animate the image view

        let imageViewToAnimate = cell.flagImageView //you can use this object to animate image view of cell


     }