###問題の概要
従来sectionによる区分けをしていなかった第1画面にsectionを加えたら、第2画面の表示にくるいが生じ前回07の質問に対する回答を頂き修正できました。
しかし、このsectionを加えることによるくるいはほかにも下記2カ所あることがわかりました。それは第1画面(View Controller)の selectedIndexPathInViewController.row を使っているからでした。
- 第2画面より第3画面に遷移するときの処理にくるいが生じ、呼んでくるウェブサイトのURLにくるいが生じました。→これはif文を使って成功裏に処理しました。
- 表示される第2画面(TableView02)の表示項目数にくるいが生じ、第2画面の表示項目が途中で切れてしまいました。→やはりif文を使ってselectedIndexPathInViewController+3.rowにする処理をしましたら、エラーがでて解決しません。
エラーの原因はif文をクラス内部で直接処理を書いている為で関数内部に書く必要があるようですが、うまく書けません。それが質問です。
第2画面の途中で切れた画面(本来なら "06.「よく使う項目」の登録"のあとに
"07.電話を受けた時の操作",
"08.呼び出し音の後の操作"]
が表示されるようにコーディングしてあります。
###作成したコード
// TableView02.swift //省略 class TableView02: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var tableView02: UITableView! var selectedIndexPathInViewController: NSIndexPath! let texts00 = ["01.電話番号で発信(動画)", "02「連絡先」の登録方法(動画)", "03「よく使う項目」の登録(動画)", //省略 override func viewDidLoad() { super.viewDidLoad() //省略 // テーブルビューのタイトルを表示 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let label = UILabel(frame: CGRect(x:0, y:50, width: tableView.bounds.width, height: 50)) //省略 return label } //ここが問題の修正箇所→ エラーがでる if selectedIndexPathInViewController.section == 1 { func tableView(tableView: UITableView, numberOfRowsInSection section:Int) -> Int { return texts[selectedIndexPathInViewController.row].count } if selectedIndexPathInViewController.section == 2 { func tableView(tableView: UITableView, numberOfRowsInSection section:Int) -> Int { return texts[selectedIndexPathInViewController.row].count } } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //省略 let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell //成功した第2画面を表示させる修正箇所 if selectedIndexPathInViewController.section == 1 { cell.label1.text = texts[selectedIndexPathInViewController.row][indexPath.row] cell.label2.text = subtexts[selectedIndexPathInViewController.row][indexPath.row] } if selectedIndexPathInViewController.section == 2 { cell.label1.text = texts[selectedIndexPathInViewController.row+3][indexPath.row] // cell.label1.text = texts[selectedIndexPathInViewController.row][indexPath.row+3] //cell.label2.text = subtexts[selectedIndexPathInViewController.row][indexPath.row+2] cell.label2.text = subtexts[selectedIndexPathInViewController.row+3][indexPath.row] } else{ } return cell } //省略 //テーブルビューのセルがタップされた処理 //成功した第3画面に遷移させる処理 var selectedIndexPath: NSIndexPath! override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if (segue.identifier == "toDetailView") { print("ここまで来た03") let subVC02 = (segue.destinationViewController as? DetailViewController)! if selectedIndexPathInViewController.section == 1 { subVC02.urlString = textsURL[selectedIndexPathInViewController.row][selectedIndexPath.row] } if selectedIndexPathInViewController.section == 2 { subVC02.urlString = textsURL[selectedIndexPathInViewController.row+3][selectedIndexPath.row] } else{ }
###エラー内容
下記の2つのエラーが出ます。
0. 冒頭のclass TableView02: UIViewController, UITableViewDataSource, UITableViewDelegate { に、
これは、テーブルビューの必要コードがないという意味と了解しています。
0. if selectedIndexPathInViewController.section == 1 { にExpected declaration というエラーがでます。これはif文をクラス内部で直接処理を書いている為で関数内部に書く必要があると了解しています。
###質問
このif文をどこにどのように書いたらよいのでしょうか。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/23 10:26