前提・実現したいこと
[超初心者????]
レシピ一覧表を作っていて、TableViewにメニューを表示するところまではなんとかできました。
次に例えば、カレーのCellを押すとカレーのレシピ、肉ジャガのCellを押すと肉ジャガのレシピが書かれた画面に遷移させたいです。
TableViewのCell自体(難しいのであれば、ボタンをつけるのでも良いです)が押せるようになってそこから新しい画面遷移を行えるようにしたです。初心者なので親切な方、コードを教えていただけると幸いです。よろしくお願いします。
発生している問題・エラーメッセージ
Invalid redeclaration of 'tableView(tableView:didSelectRowAtIndexPath:)'
該当のソースコード
import UIKit class TableViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{ @IBOutlet var MyTV: UITableView! let TODO = ["カレー","肉ジャガ","野菜炒め"] override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return TODO.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for:indexPath) cell.textLabel?.text = TODO[indexPath.row] return cell } private func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == 0{ let targetViewController = self.storyboard!.instantiateViewController(withIdentifier: "curry") self.present(targetViewController, animated: true, completion: nil) } } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == 1{ let targetViewController = self.storyboard!.instantiateViewController(withIdentifier: "nikuzyaga") self.present(targetViewController, animated: true, completion: nil) } } }
補足情報(FW/ツールのバージョンなど)
画像のように
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 1{
let targetViewController = self.storyboard!.instantiateViewController(withIdentifier: "nikuzyaga")
self.present(targetViewController, animated: true, completion: nil)
}
}
の部分にエラーコードが出ます。
初心者並みに考えてみるとcellの番号を取得するのかなと思います。
もしそうであれば、この場合のCell番号取得のコードを分かりやすく教えていただけると幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。