質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

2回答

559閲覧

tableviewのcellをタップしてsegueから画面遷移したいです。

ROKIDOG

総合スコア20

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/11/08 00:30

前提・実現したいこと

PictureViewControllerarというところからPictureSideMenuというサイドメニューのようなものを呼び出しています。
このPictureSideMenuのtableviewのcellをタップしてsegueから画面遷移したいです。

発生している問題・エラーメッセージ

エラーメッセージ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<Like_.PictureSidemenuViewController: 0x7f9863d31340>) has no segue with identifier 'toPost''

segueのidentifierはtoPostと設定しているのですがこういったエラーが出てしまいます、、

###コード
PictureSideMenu(ここで次のPictureKindViewControllerへ画面遷移したいです)

protocol PictureSidemenuViewControllerDelegate: class { func parentViewControllerForSidemenuViewController(_ sidemenuViewController: PictureSidemenuViewController) -> UIViewController func shouldPresentForSidemenuViewController(_ sidemenuViewController: PictureSidemenuViewController) -> Bool func sidemenuViewControllerDidRequestShowing(_ sidemenuViewController:PictureSidemenuViewController, contentAvailability: Bool, animated: Bool) func sidemenuViewControllerDidRequestHiding(_ sidemenuViewController: PictureSidemenuViewController, animated: Bool) func sidemenuViewController(_ sidemenuViewController: PictureSidemenuViewController, didSelectItemAt indexPath: IndexPath) } class PictureSidemenuViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet var tabaleview : UITableView! let menu : [String] = ["閉じる","犬","猫","小動物","鳥類","爬虫類","両生類","魚類","その他"] private let contentView = UIView(frame: .zero) private let tableView = UITableView(frame: .zero, style: .plain) private var screenEdgePanGestureRecognizer: UIScreenEdgePanGestureRecognizer! private var panGestureRecognizer: UIPanGestureRecognizer! weak var delegate: PictureSidemenuViewControllerDelegate? private var beganLocation: CGPoint = .zero private var beganState: Bool = false var isShown: Bool { return self.parent != nil } private var contentMaxWidth: CGFloat { return view.bounds.width * 0.8 } private var contentRatio: CGFloat { get { return contentView.frame.maxX / contentMaxWidth } set { let ratio = min(max(newValue, 0), 1) contentView.frame.origin.x = contentMaxWidth * ratio - contentView.frame.width contentView.layer.shadowColor = UIColor.black.cgColor contentView.layer.shadowRadius = 3.0 contentView.layer.shadowOpacity = 0.8 view.backgroundColor = UIColor(white: 0, alpha: 0.3 * ratio) } } override func viewDidLoad() { super.viewDidLoad() //tableviewの不要な線を消す tableView.tableFooterView = UIView() var contentRect = CGRect(x: view.bounds.minX, y: view.bounds.minY, width: view.bounds.width, height: view.bounds.height*0.73) contentRect.size.width = contentMaxWidth contentRect.origin.x = -contentRect.width contentView.frame = contentRect contentView.backgroundColor = .white contentView.autoresizingMask = .flexibleHeight view.addSubview(contentView) tableView.frame = contentView.bounds tableView.separatorInset = .zero tableView.dataSource = self tableView.delegate = self tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell") contentView.addSubview(tableView) tableView.reloadData() let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(backgroundTapped(sender:))) tapGestureRecognizer.delegate = self view.addGestureRecognizer(tapGestureRecognizer) } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row == 0 { hideContentView(animated: true) { (_) in self.willMove(toParent: nil) self.removeFromParent() self.view.removeFromSuperview() } } else { self.performSegue(withIdentifier: "toPost", sender: nil) } tableView.deselectRow(at: indexPath, animated: true) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "toPost" { let pictureKindViewController = segue.destination as! PictureKindViewController let selectedIndexPath = tableView.indexPathForSelectedRow pictureKindViewController.selectedAnimal = menu[(selectedIndexPath?.row)!] } } func showContentView(animated: Bool) { if animated { UIView.animate(withDuration: 0.3) { self.contentRatio = 1.0 } } else { contentRatio = 1.0 } } func hideContentView(animated: Bool, completion: ((Bool) -> Swift.Void)?) { if animated { UIView.animate(withDuration: 0.2, animations: { self.contentRatio = 0 }, completion: { (finished) in completion?(finished) }) } else { contentRatio = 0 completion?(true) } } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return menu.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = menu[indexPath.row] return cell } func startPanGestureRecognizing() { if let parentViewController = self.delegate?.parentViewControllerForSidemenuViewController(self) { screenEdgePanGestureRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(panGestureRecognizerHandled(panGestureRecognizer:))) screenEdgePanGestureRecognizer.edges = [.left] screenEdgePanGestureRecognizer.delegate = self parentViewController.view.addGestureRecognizer(screenEdgePanGestureRecognizer) panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognizerHandled(panGestureRecognizer:))) panGestureRecognizer.delegate = self parentViewController.view.addGestureRecognizer(panGestureRecognizer) } } @objc private func panGestureRecognizerHandled(panGestureRecognizer: UIPanGestureRecognizer) { guard let shouldPresent = self.delegate?.shouldPresentForSidemenuViewController(self), shouldPresent else { return } let translation = panGestureRecognizer.translation(in: view) if translation.x > 0 && contentRatio == 1.0 { return } let location = panGestureRecognizer.location(in: view) switch panGestureRecognizer.state { case .began: beganState = isShown beganLocation = location if translation.x >= 0 { self.delegate?.sidemenuViewControllerDidRequestShowing(self, contentAvailability: false, animated: false) } case .changed: let distance = beganState ? beganLocation.x - location.x : location.x - beganLocation.x if distance >= 0 { let ratio = distance / (beganState ? beganLocation.x : (view.bounds.width - beganLocation.x)) let contentRatio = beganState ? 1 - ratio : ratio self.contentRatio = contentRatio } case .ended, .cancelled, .failed: if contentRatio <= 1.0, contentRatio >= 0 { if location.x > beganLocation.x { showContentView(animated: true) } else { self.delegate?.sidemenuViewControllerDidRequestHiding(self, animated: true) } } beganLocation = .zero beganState = false default: break } } } extension PictureSidemenuViewController: UIGestureRecognizerDelegate { internal func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { let location = gestureRecognizer.location(in: tableView) if tableView.indexPathForRow(at: location) != nil { return false } return true } }

ストーリーボード
イメージ説明)

試したこと

segueの遷移先のクラスが設定しているか
segueの名前がtoPostになっているか
tableviewのcellのidentifierがあっているか

どなたかアドバイス頂けると嬉しいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

記載がないので想像ですが、PictureSidemenuViewController の生成方法に問題があるのではないでしょうか?
PictureSidemenuViewController() こんな感じでかいていないでしょうか?

storyboardから生成する場合は下記が参考になると思います。
StoryBoardのViewControllerをインスタンス化する

少し古い記事なので多少の書き換えは必要になると思います。

投稿2019/11/10 11:08

usagi001

総合スコア208

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

Segue使ったことないので、当てずっぽうですが、

self.performSegue(withIdentifier: "toPost", sender: nil)

のようにPictureSidemenuViewControllerのインスタンスからperformSegueを呼び出すと駄目なのでしょうね。
サイドメニューを呼び出しているPictureViewControllerarクラスのインスタンスを使ってperformSegueを呼び出せばいけるのではないかと思います。

投稿2019/11/08 08:08

takabosoft

総合スコア8356

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ROKIDOG

2019/11/08 13:40

ご回答ありがとうございます! PictureViewControllerarのなかで処理を行うという事ですかね? PictureViewControllerarのextension PictureViewController: PictureSidemenuViewControllerDelegate に func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { performSegue(withIdentifier: "toPost", sender: nil) }と書いてみたのですがうまくいきませんでした、、 理解力無くてすみません、、、
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問