prepareForSegueで変数の受け渡しをする場合は、ページ遷移することはできるのですが、
変数の受け渡しをするのではなく、リスト表示から単純にそれぞれ別の子ページへ遷移するには、どうすればよいでしょうか?Segueの名前を定義し、それぞれの遷移先のページも作成し、下記のコードにしたところ、
0行目を選択した場合、①0行目の子ページ表示→②0行目の子ページ表示
1行目を選択した場合、①0行目の子ページ表示→②1行目の子ページを表示
2行目を選択した場合、①0行目の子ページ表示→②2行目の子ページを表示
と2ページ移動してしまいます。
そもそも、tableviewでリスト表示するべきではなく、各々のリンクをUiLabelを縦に並べて作成すべきでなのでしょうか?それとも、私のコードがおかしいだけでしょうか?
どうぞよろしくお願いいたします。
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{ func tableView(table: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) if indexPath.row == 0 { cell.textLabel!.text = "0行目" }else if indexPath.row == 1 { cell.textLabel!.text = "1行目" }else if indexPath.row == 2 { cell.textLabel!.text = "2行目" } return cell } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == 0 {//0行目 performSegueWithIdentifier("zeroSegue", sender: indexPath.row) }else if indexPath.row == 1 {//1行目 performSegueWithIdentifier("firstSegue", sender: indexPath.row) }else if indexPath.row == 2 {//2行目 performSegueWithIdentifier("secondSegue", sender: indexPath.row) } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/02/08 00:46