标签:
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
override func viewDidLoad() {
super.viewDidLoad()
let mytableView = UITableView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height), style: UITableViewStyle.Plain)
self.view.addSubview(mytableView)
mytableView.delegate = self
mytableView.dataSource = self
mytableView.backgroundColor = UIColor.whiteColor()
// Do any additional setup after loading the view, typically from a nib.
}
//行数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}
//cell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = UITableViewCell()
cell.textLabel?.text = "少停"
cell.detailTextLabel?.text = "gaga"
if indexPath.row%2 == 0{
cell.imageView?.image = UIImage(named: "image1")
}else{
cell.imageView?.image = UIImage(named: "image2")
}
return cell
}

标签:
原文地址:http://www.cnblogs.com/shaoting/p/5085178.html