importUIKit
classViewController:UIViewController{
overridefuncviewDidLoad() {
super.viewDidLoad()
//style:(1).Plain分區(qū)之間沒有間距(2).Group分區(qū)之間有間距
lettableView:UITableView=UITableView(frame:view.bounds, style: .Plain)
//提供視圖相關(guān)操作
tableView.delegate=self
//設(shè)置數(shù)據(jù)源代理(負責(zé)提供數(shù)據(jù))
tableView.dataSource=self
view.addSubview(tableView)
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//遵循多個協(xié)議采用,隔開
extensionViewController:UITableViewDelegate,UITableViewDataSource{
//返回每個分區(qū)的行數(shù)
functableView(tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
return30
}
//返回每個單元格,單元格:UITableViewCell舷蒲,NSIndexPath是存儲該單元格是第幾分區(qū)·第幾行
functableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) ->UITableViewCell{
letcell =UITableViewCell()
cell.textLabel?.text="老司機"
returncell
}
}