26
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swiftで最低限の TableViewControllerを実装してみた。

Last updated at Posted at 2014-06-09

ちなみに、Storyboardを使わない例です。
delegate = self しています。

MyTableViewController.swift
import Foundation
import UIKit

class MyTableViewController :UITableViewController, 
                             UITableViewDelegate, 
                            UITableViewDataSource
{
    let TableViewCellIdentifier:String = "CELL"

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        var myTableView:UITableView = 
            UITableView(frame: self.view.bounds, 
                        style: UITableViewStyle.Plain);
        
        myTableView.registerClass(UITableViewCell.self,
                                 forCellReuseIdentifier:TableViewCellIdentifier)
        
        myTableView.delegate = self;
        myTableView.dataSource = self;
        
        self.view.addSubview(myTableView)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func tableView(tableView: UITableView!, 
                            numberOfRowsInSection section: Int) -> Int {
        return 12;
    }

    override func tableView(tableView: UITableView!,
                           cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    
        var cell:UITableViewCell = UITableViewCell(
                                    style: UITableViewCellStyle.Subtitle,
                                    reuseIdentifier:TableViewCellIdentifier )
        cell.textLabel.text = "Cell No. \(indexPath.row)"
        cell.detailTextLabel.text = "Subtitle No. \(indexPath.row)"
        return cell;
    }
}
26
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?