#author("2016-05-30T14:42:59+09:00","default:wikiwriter","wikiwriter") [[UIKit/テーブル]] &tag(UIKit/テーブル/基本); *目次 [#y19c908f] #contents *関連ページ [#p7b3b4be] *参考情報 [#o9ac69a3] *基礎: Single View ApplicationでUITableViewControllerから始める方法 [#n5114e1e] -Single View Applicationを生成。 -UITableViewControllerのサブクラスを追加(ex: MyTableViewController)。 -Main.storyboardを開き、既存のView Controllerを削除。 -Table View Controllerをストーリーボードにドロップして追加。 -そのクラスをMyTableViewControllerとする。 *UITableViewを使って実装(ストーリーボード) [#o41cfc7a] -該当するViewControllerをデータソース、Delegate先とする場合、以下のようになる。 #pre{{ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @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 } 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() return cell } override func setEditing(editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated) tableView.setEditing(editing, animated: animated) } } }}