前提・実現したいこと
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があっているか
どなたかアドバイス頂けると嬉しいです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。