|
|
| (同じ利用者による、間の14版が非表示) |
| 1行目: |
1行目: |
| ==storyboardを使ってTableViewを追加==
| | [[ios/swift/TableView/表示]] |
| #sotryboardにTableViewを貼り付ける
| |
| #TableViewオブジェクトをViewControllerに紐付ける
| |
| #以下を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
| |
| }
| |
| #tableViewのメソッドを使えるようにインターフェイスを実装する
| |
| -class ViewController: UIViewController
| |
| +class ViewController: UIViewController, UITableViewDataSource,UITableViewDelegate {
| |
|
| |
|
| 参考:http://www.dcom-web.co.jp/technology/swift3/
| | [[ios/swift/TableView/画像付き]] |
|
| |
|
| ==画像付きTableViewの作成==
| | [[ios/swift/TableView/API画像連動]] |
| #sotryboardにTableViewを貼り付ける
| | |
| #TableViewオブジェクトをViewControllerに紐付ける
| | [[ios/swift/TableView/API画像連動スクロール読み込み]] |
| #TableViewの中のTableViewCellにImageViewとLabelViewを貼り付ける
| | |
| #TableViewCellのIdentifierを"CustomCell"とする。(Identityではないので気をつける)
| | [[ios/swift/TableView/高さ自動調節]] |
| #TableViewCellのClass名をを"CustomTableViewCell"とする
| | |
| #CocoaTouchClassのファイルを作成し"CustomTableViewCell"の名前で以下のように編集。
| | [[ios/swift/TableView/画面遷移]] |
| #labelとimageのオブジェクトの紐付けも行う。
| | |
| class CustomTableViewCell: UITableViewCell {
| | [[ios/swift/TableView/Pull更新]] |
| @IBOutlet weak var customLabelView: UILabel!
| | |
| @IBOutlet weak var customImageView: UIImageView!
| | [[ios/swift/TableView/スクロール上下検知]] |
| }
| | |
| #ViewControllerに以下を追加
| | [[ios/swift/TableView/削除並替処理]] |
| func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
| |
| // セルを取得
| |
| let cell =
| |
| tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomTableViewCell
| |
| cell.customImageView.image = UIImage(named:"prof400.png")
| |
| cell.customLabelView.text = "hoge"
| |
| return cell
| |
| }
| |
| 参考:http://yuu.1000quu.com/use_a_custom_cell_in_swift
| |