tableviewを使い、項目ごとに分けたいと思っています。項目は4つあります。
しかし下記のコードですと最初の項目しか表示されず困っています。解決策をご存知の方、教えて下さい。よろしくお願います。
DiaryViewController
1import UIKit 2 3class DiaryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource 4{ 5 @IBAction func back(_ sender: Any) 6 { 7 self.dismiss(animated: true, completion: nil) 8 } 9 10 @IBOutlet weak var tableView: UITableView! 11 12 let diaryCell:[String] = ["最初の項目", "二番目の項目", "三番目の項目", "四番目の項目"] 13 14 15 override func viewDidLoad() 16 { 17 super.viewDidLoad() 18 } 19 20 func numberOfSectionsInTableView(tableView: UITableView) -> Int 21 { 22 return diaryCell.count 23 } 24 25 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 26 { 27 return diaryCell[section] 28 } 29 30 31 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 32 { 33 return 1 34 } 35 36 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 37 { 38 let cell = tableView.dequeueReusableCell(withIdentifier: "1", for: indexPath) 39 return cell 40 } 41 42 43 44 /* 45 // MARK: - Navigation 46 47 // In a storyboard-based application, you will often want to do a little preparation before navigation 48 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 49 // Get the new view controller using segue.destination. 50 // Pass the selected object to the new view controller. 51 } 52 */ 53 54} 55
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/24 04:33