ios - 如何从 didSelectRowAtindexPath : function 访问单元格 imageView

标签 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)
    }

最佳答案

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


     }

关于ios - 如何从 didSelectRowAtindexPath : function 访问单元格 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55487756/

相关文章:

ios - 为什么我得到 "Swift Dynamic Cast Failed"? :/

objective-c - 在 Swift 中声明自引用指针

ios - 如何在 swift 4 中添加虚折线?

iphone - 根据 iOS 应用程序中的设置重新加载 UITableView

ios - lazy var属性被初始化两次正常吗?

ios - 在 Controller 之间传递数据显示错误

ios - 如何过滤swiftyjson数组

ios - 加载更多事件单元格 CollectionViewCell

objective-c - cellForRowAtIndexPath 在每个部分下获取正确的数据

iphone - 如何从非 navcontroller View 打开 navcontroller?