HogeCell(UICollectionViewCell)からHugaController(UICollectionViewController)へ遷移する方法が分かりません。
コンソールでボタンのタップ反応は確認できたのですが、
//ボタン 箇所の定義方法が分からないためRUNできません。
原因がわからないため質問します。
よろしくお願いします。
import UIKit class HogeCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .red setup() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } let button: UIButton = { let btn = UIButton() btn.setTitle("push", for: .normal) btn.tintColor = UIColor.white btn.backgroundColor = UIColor.green btn.translatesAutoresizingMaskIntoConstraints = false return btn }() private func setup() { addSubview(button) button.addTarget(self, action: #selector(onClickButton(_:)), for: .touchUpInside) button.anchor //...省略してます } //ボタン @objc func onClickButton(_ sender: UIButton){ print("タップ!") let huga = HugaController()//遷移したい先です let hoge = HogeController()//HogeCellをレジスターしてます let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width:frame.width, height:frame.height) huga.collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout) hoge.navigationController?.pushViewController(huga, animated: true) } }
コメントを頂き、数日調べていますが全く分かりません。
//追記しました。
下記の様に書きましたが、セルを乗せているUICollectionViewController(HogeController)からUINavigationControllerを取得できません。
RUNできますが、タップしても無反応です。
//ボタン @objc func onClickButton(_ sender: UIButton){ print("タップ!") let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width:frame.width, height:frame.height) let navigationController = UINavigationController(rootViewController: HogeController()) navigationController.pushViewController(HugaController(collectionViewLayout: layout), animated: true) }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/20 14:30 編集
2018/04/20 14:33
退会済みユーザー
2018/04/21 04:37
退会済みユーザー
2018/04/21 08:27 編集
2018/04/21 09:38
退会済みユーザー
2018/04/25 02:41
2018/04/25 02:49
退会済みユーザー
2018/04/25 05:51
2018/04/25 05:56
2018/04/25 05:57
退会済みユーザー
2018/04/25 06:04