「Ios/swift/TableView」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
編集の要約なし
編集の要約なし
8行目: 8行目:
         super.viewDidLoad()
         super.viewDidLoad()
         testTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
         testTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
        testTableView.delegate = self
        testTableView.dataSource = self
     }
     }
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
17行目: 19行目:
         return cell
         return cell
     }
     }
#クラスを継承する
-class ViewController: UIViewController
+class ViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate {


参考:http://www.dcom-web.co.jp/technology/swift3/
参考:http://www.dcom-web.co.jp/technology/swift3/

2016年6月22日 (水) 22:08時点における版

storyboardを使ってTableViewを追加

  1. sotryboardにTableViewを貼り付ける
  2. TableViewオブジェクトをViewControllerに紐付ける
  3. TableViewのdatagateとdatasourceをViewControllerに紐付ける(TableViewオブジェクトを選択し、ViewControllerの上3つのボタンの一番左にcontrolボタンで紐付ける)
  4. 以下をViewController.swiftに追加
   @IBOutlet weak var testTableView: UITableView!
   override func viewDidLoad() {
       super.viewDidLoad()
       testTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
       testTableView.delegate = self
       testTableView.dataSource = self
   }
   func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return 10
   }
   func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
       let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
       cell.textLabel?.text = String(indexPath.row + 1) + "データ"
       return cell
   }
  1. クラスを継承する
-class ViewController: UIViewController
+class ViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate {

参考:http://www.dcom-web.co.jp/technology/swift3/