私はアプリケーション内で2つのView Controllerをリンクしようとしていますが、テーブルビューのセルに接続しないでリンクする方法を理解できません。私はそれが単なる識別子付きのシガーになりたいので、識別子でperfrom segueを呼び出すことができます。しかし、私はセルから次のView ControllerにドラッグすることでSegueを作成することしかできません。リンクなしのVC間のSwift Segue
ここでは、リンクしようとしている2つのVCのイメージを示します。選択されているセルが表示されます。
http://imgur.com/gallery/PWJol
私はこれを行う方法を見つけ出すことはできません。
これは正しいと思われるsegueに使用しているコードです。私は行が選択されたときにそれをセグにし、選択された行のラベル名を渡したい。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.NameToPass = DietSelectionTableViewCell.TypesOfDiets[indexPath.row]
self.performSegue(withIdentifier: "DietInformation", sender: self)
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "DietInformation" {
if let destinationVC = segue.destination as? DietInformationViewController {
destinationVC.DietTypeLabelText = self.NameToPass
}
}
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
、オレンジの上部にあるサークル(ビューコントローラ自体を表す)とドラッグをCtrlキーを押しながらクリックします。繰り返しますが、私はあなたがコントロールドラッグしなければならないから事を強調してきましたビューコントローラに接続します。 – pbasdf