2017-01-18 3 views
0

私は自分のTableViewCellをVersionCellVCという独自のクラスに持っています。UITableViewCellクラスにあるUIImageViewをタップするときに新しい画面を開くには?

私は自分のUIImageViewをセルを完全に隠しています。ユーザはTableViewCellではなくUIImageViewをタップするしかありません。

私はsegueを実行するか、またはvcを提示したいと思います。ジェスチャ認識機能とそれが呼び出す関数を既に作成しています。しかし、私はUITableViewCellのカスタムサブクラスに入っているので、UITableViewCellクラスのメンバーではないため、present(vc:animate:complete)prepare(forSegue:..:))の関数を使用することはできません。

UIImageViewをUIButtonに変更せずにこれを解決するにはどうすればよいですか?

答えて

0

このような(テーブルビューを含むviewcontroller内の)何かについてはどうですか?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomCell 

    cell.myImageView?.isUserInteractionEnabled = true 
    cell.myImageView?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageViewTapped(imageView:)))) 

    return cell 
} 

func imageViewTapped(imageView: UIImageView) { 
    if let indexPath = tableView.indexPathForRow(at: imageView.convert(.zero, to: tableView)) { 
     print("user tapped imageview at indexPath \(indexPath)") 
    } 
} 
関連する問題