私のカスタムCollectionViewCellでperformsegueメソッドを呼び出す際に問題が発生しています。私のビュー階層はUIView-UITableView-UICollectionViewです。テーブルビューは、私の "CustomTableViewCell"内のコレクションビューを持つ静的なテーブルビューです。私はtvOSを使用しているので、私はcollectionview(didSelectCell)関数の代わりにUITapGestureRecognizerを使用する必要があります。私の印刷機能が働いているので、私の知っている "タップ"は正しく機能しているので、 "self.performsegue"という行を追加すると "CustomTableViewCell型の値にperfromSegue"という型の値がありません。私は、セルから次のビューにセグをドラッグしてコントロールしようとしましたが、それでも何もしませんでした。私はそれが私の "CustomTableViewCell"クラスのタイプと関係していると思いますが、それ以外に何を追加するか分かりません。ネストされたTableViewControllerでtvOSが実行されます
ジェスチャーを追加した項目のセル:
func tapped(_ gesture: UITapGestureRecognizer){
if let cell = gesture.view as? PostCollectionViewCell {
//load next view pass movie
guard let post = cell.post else {return;}
print("\(post.title) tapped")
self.performSegue(withIdentifier: "toPost", sender: post)
}
}
:ここ
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "postCell", for: indexPath) as! PostCollectionViewCell
if cell.gestureRecognizers?.count == nil {
let tap = UITapGestureRecognizer(target: self, action: #selector(CustomTableViewCell.tapped(_:)))
tap.allowedPressTypes = [NSNumber(value: UIPressType.select.rawValue)]
cell.addGestureRecognizer(tap)
}
がタップ方法であり、
私はself.performsegueをcell.perfomsegueに置き換えようとしました。なぜなら、技術的には私の情報が "perfromSegue(identifier :)"メソッドに渡されるからです。最後に私が考えていたのは、元のViewControllerであるCustomTableViewCellの親ビューを何とか呼び出すことですが、sharedControllerを作成するとViewControllerまたはViewController.sharedControllerで.performsegueを呼び出すことはできません。