###前提・実現したいこと
Navigation itemのBar Button Item の add を押して tableViewを追加していきたい
ここに質問したいことを詳細に書いてください
ビルドは成功するのに、画面右上のaddボタンを押してもテーブルが追加されない
###該当のソースコード
Swift
1import UIKit 2 3class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 @IBOutlet weak var tableView: UITableView! 6 7 //ボタンが押された時にデータを追加する処理 8 9 var dataArray :[Int] = [] 10 11 @IBAction func add(sender: UIBarButtonItem) { 12 13 dataArray.append(dataArray.count) 14 tableView.reloadData() 15 16 } 17 18 //TableViewの各セクションのセルの数を返す 19 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 20 return dataArray.count 21 } 22 23 //各セルの内容を返す 24 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 25 //再利用可能なcellを得る 26 let cell: UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell") 27 28 //Cellに値を設定する 29 cell.textLabel?.text = "Row \(indexPath.row)" 30 cell.detailTextLabel?.text = "Subtitle \(indexPath.row)" 31 32 return cell 33 } 34 35 36 override func viewDidLoad() { 37 super.viewDidLoad() 38 // Do any additional setup after loading the view, typically from a nib. 39 } 40 41 override func didReceiveMemoryWarning() { 42 super.didReceiveMemoryWarning() 43 // Dispose of any resources that can be recreated. 44 } 45 46 47} 48
###試したこと
返り値を以下のように変更してはじめから10個のセルを表示させてる状態にしてみるも変わらず一つもセルが表示されないという状態です。
エラーも相変わらず出なくてビルドは成功します
return dataArray.count
⬇️
return 10
###補足情報(言語/FW/ツール等のバージョンなど)
xcode7 swift mac os x バージョン10.11.6
以下、githubで公開しています
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/12 04:15 編集
2016/09/12 04:20
2016/09/12 05:13