「Ios/swift/TableView」の版間の差分
ナビゲーションに移動
検索に移動
ページの作成:「==storyboardを使ってTableViewを追加== #sotryboardにTableViewを貼り付ける #TableViewオブジェクトをViewControllerに紐付ける #TableViewのdatagate...」 |
編集の要約なし |
||
| 17行目: | 17行目: | ||
return cell | return cell | ||
} | } | ||
参考:http://www.dcom-web.co.jp/technology/swift3/ | |||
2016年6月22日 (水) 21:38時点における版
storyboardを使ってTableViewを追加
- sotryboardにTableViewを貼り付ける
- TableViewオブジェクトをViewControllerに紐付ける
- TableViewのdatagateとdatasourceをViewControllerに紐付ける(TableViewオブジェクトを選択し、ViewControllerの上3つのボタンの一番左にcontrolボタンで紐付ける)
- 以下をViewController.swiftに追加
@IBOutlet weak var testTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
testTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
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
}