質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

3833閲覧

UITableViewで画面遷移後のセルの選択状態解除

bacchi

総合スコア13

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2016/12/07 04:49

###前提・実現したいこと
UITableViewでセルを選択して画面遷移した後、前の画面に戻った時にセルの選択状態を解除したいと思っています。

以下のエラーメッセージが、該当のソースコードの"// ここにエラー"と書いた2ヶ所に出ています。
解決方法を教えてください。

###発生しているエラーメッセージ

Ambiguous reference to member 'tableView(_:numberOfRowsInSection:)'

###該当のソースコード

swift

1import UIKit 2 3class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 @IBOutlet weak var Label2: UILabel! 6 7 // Tableで使用する配列を設定する 8 private let myItems: NSArray = ["いて座", "うお座", "おうし座", "おおいぬ座", "おおぐま座", "おとめ座", "おひつじ座", "オリオン座", "カシオペア座", "かに座", "こいぬ座", "こぐま座", "こと座", "さそり座", "しし座", "てんびん座", "はくちょう座", "ふたご座", "みずがめ座", "やぎ座", "わし座"] 9 10 11 override func viewDidLoad() { 12 super.viewDidLoad() 13 14 Label2.text = "探したい星座を選ぼう!" 15 } 16 17 override func didReceiveMemoryWarning() { 18 super.didReceiveMemoryWarning() 19 // Dispose of any resources that can be recreated. 20 } 21 22 override func viewWillAppear(_ animated: Bool) { 23 super.viewWillAppear(animated) 24 25 if let indexPathForSelectedRow = tableView.indexPathForSelectedRow { // ここにエラー 26 tableView.deselectRowAtIndexPath(indexPathForSelectedRow, animated: true) 27 } 28 } 29 30 override func viewDidAppear(_ animated: Bool) { 31 super.viewDidAppear(animated) 32 if let indexPathForSelectedRow = tableView.indexPathForSelectedRow { // ここにエラー 33 tableView.deselectRowAtIndexPath(indexPathForSelectedRow, animated: true) 34 } 35 } 36 37 // Cellの総数を返す. 38 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 39 return myItems.count 40 } 41 42 // Cellに値を設定する 43 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 44 // 再利用するCellを取得する. 45 let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath as IndexPath) 46 47 // Cellに値を設定する. 48 cell.textLabel!.text = "\(myItems[indexPath.row])" 49 50 return cell 51 } 52 53 // Cellが選択された際に呼び出される 54 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 55 print("Num: \(indexPath.row)") 56 print("Value: \(myItems[indexPath.row])") 57 58 let storyboard: UIStoryboard = self.storyboard! 59 let nextView = storyboard.instantiateViewController(withIdentifier: "third") as! ThirdViewController 60 61 let seizaNum = indexPath.row 62 63 let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate 64 appDelegate.seizaNum = seizaNum 65 66 self.present(nextView, animated: true, completion: nil) 67 } 68 69 @IBAction func backToSecond(segue: UIStoryboardSegue) {} 70 71 /* 72 // MARK: - Navigation 73 74 // In a storyboard-based application, you will often want to do a little preparation before navigation 75 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 76 // Get the new view controller using segue.destinationViewController. 77 // Pass the selected object to the new view controller. 78 } 79 */ 80}

###試したこと
エラーの意味がわからなかったので調べてみましたが解決できませんでした。

###補足情報(言語/FW/ツール等のバージョンなど)
Swift3.0
Xcode8.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

tableViewという名前でUITableViewのOutletを作って下さい。

投稿2016/12/07 04:54

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問