Tag: UIKit/テーブル
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) } }
override func numberOfSectionsInTableView(tableView: UITableView!) -> Int { return 1 } override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { return self.items.count }
override func viewDidLoad() { super.viewDidLoad() self.tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0) self.tableView.backgroundColor = UIColor.grayColor() }