collectinviewのcellを押した時に画面遷移をしたいです。
collectinviewのcellを押した時にUserPostViewControllerというクラスへ画面遷移し移動先(UserPostViewController)のcommentTextViewにUserPageViewControllerのcommentText を入れたいです。
performSegueのwithIdentifier が "toPost"であり、遷移先のクラスがUserPostViewControllerであるのも確認しました。
しかしcellを押しても遷移すらしてくれないです。
どういった対処が必要でしょうか??
追記
初めに投稿したものはsegueのdestinationの書き方が間違えており、今回編集済みです。
しかし、遷移できなかったので、アドバイス頂けると幸いです。
class UserPageViewController: UIViewController, UICollectionViewDataSource ,UICollectionViewDelegate{ var posts = [Post]() var commentText :String = "" @IBOutlet var userImageView: UIImageView! @IBOutlet var userDisplayNameLabel: UILabel! @IBOutlet var userIntroductionTextView: UITextView! @IBOutlet var photoCollectionView : UICollectionView! @IBOutlet var postCountLabel: UILabel! @IBOutlet var followerCountLabel: UILabel! @IBOutlet var followingCountLabel: UILabel! func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { commentText = posts[indexPath.row].text performSegue(withIdentifier: "toPost", sender: nil) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "toPost"{ let userPostViewController = segue.destination as! UserPostViewController userPostViewController.commentText = commentText } }
移動先
class UserPostViewController: UIViewController { var commentText:String? @IBOutlet var userImageView: UIImageView! @IBOutlet var userNameLabel: UILabel! @IBOutlet var photoImageView: UIImageView! @IBOutlet var commentTextView: UITextView! @IBOutlet var timestampLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() commentTextView.text = commentText userImageView.layer.cornerRadius = userImageView.bounds.width / 2.0 userImageView.clipsToBounds = true }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/20 03:35
2019/08/20 14:50 編集
2019/08/22 09:22
2019/08/23 06:13 編集
2019/08/25 10:16
2019/08/25 12:57
2019/08/26 04:50