以下のコード内のセルの個数を指定するデリゲートメソッドか、
セルに値を設定するデータソースメソッドが正しくないのか、
シュミレータでの情報の出力時に想定と違う出力のされ方をしてしまいます。
swift
1import UIKit 2 3class UserInfoViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 //テーブルに表示させたい中身の宣言 6 let selections = ["職業","会社名","性別","年齢"] 7 8 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 // Do any additional setup after loading the view. 14 } 15 16 override func didReceiveMemoryWarning() { 17 super.didReceiveMemoryWarning() 18 // Dispose of any resources that can be recreated. 19 } 20 21 22 //Table Viewのセルの数を指定 23 func tableView(_ table: UITableView, 24 numberOfRowsInSection section: Int) -> Int { 25 return selections.count 26 } 27 28 29 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 30 // セルを取得する 31 let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 32 // セルに表示する値を設定する 33 cell.textLabel!.text = selections[indexPath.row] 34 35 print(selections[indexPath.row]) 36 return cell 37 } 38 39 40 /* 41 // MARK: - Navigation 42 43 // In a storyboard-based application, you will often want to do a little preparation before navigation 44 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 45 // Get the new view controller using segue.destinationViewController. 46 // Pass the selected object to the new view controller. 47 } 48 */ 49 50}
想定した出力内容)
セルを4つだけ表示して、各項目下に下線が惹かれている。
実際の出力内容)
項目以上のセルが出力されている + 会社名と性別の間に下線が表示されてしまっている。
下線が各項目に下に表示されて、セルの数も項目数のみに指定したい場合は
どのような書き方をすればよろしいでしょうか。
ご教授の程よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/10 03:26