#author("2017-01-24T14:35:04+09:00","default:wikiwriter","wikiwriter")
&tag(UIKit/テーブル);
*目次 [#sc69111a]
#contents
*関連ページ [#pe99027a]
-[[Storyboard]]
-[[./基本]]
-[[./セルの再利用]]
-[[./セルのカスタマイズ]]
-[[./セルを共有する]]
-[[./Static Cellsを使用する]]
-[[./セル内に置かれたボタンのイベントを処理する]]
-[[./空状態を表現する]]
-[[./Tips]]

*参考情報 [#w10c3f1c]

*概要 [#e44ab7b1]
-Swiftでテーブルビューを実装する方法

*UITableViewを使って実装(ストーリーボード) [#o41cfc7a]
-該当するViewControllerをデータソース、Delegate先とする場合、以下のようになる。
*サンプル [#a8f334ba]

**UITableViewControllerの基礎 [#o6dfe1e6]
-三行のデータを表示するサンプル。
#pre{{
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
class TableViewBasicViewController: UITableViewController {

    var rows = ["aaa", "bbb", "ccc"]
    
    @IBOutlet weak var tableView: UITableView!
    
    var objects = ["まぐろ", "サーモン", "えび", "はまち", "いか", "うなぎ"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.navigationItem.rightBarButtonItem = self.editButtonItem()
        tableView.backgroundColor = UIColor.grayColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objects.count

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "myCell")
        cell.textLabel?.text = objects[indexPath.row]
        cell.backgroundColor = UIColor.brownColor()

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return rows.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
        cell.textLabel?.text = rows[indexPath.row]
        return cell
    }
    
    override func setEditing(editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
        tableView.setEditing(editing, animated: animated)
        
    }
}
}}


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS