override func viewDidLoad() {
super.viewDidLoad()
names = ["張三", "李四", "王五", "趙六"]
//.Plain樣式默認沒有分隔
let tableView = UITableView(frame: self.view.bounds, style: .Grouped)
tableView.dataSource = self
tableView.delegate = self
self.view.addSubview(tableView)
//Cell、Header、Footer寬度一定與TableView相同
//x/y/width無效
let headView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100))
headView.backgroundColor = UIColor.redColor()
tableView.tableHeaderView = headView
let footView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100))
footView.backgroundColor = UIColor.greenColor()
tableView.tableFooterView = footView
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
//詢問某個section中有多少條數據
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names!.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//同一個Cell對象會重復使用
//1. 在隊列中獲取空閑的Cell
var cell = tableView.dequeueReusableCellWithIdentifier("cell")
if cell == nil {
//2. 創建可以重用的Cell對象
cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
}
//3. 設置內容
cell?.textLabel?.text = names![indexPath.row]
// cell?.detailTextLabel?.text = "xxxxx"
return cell!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(indexPath.section, indexPath.row)
print(names![indexPath.row])
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = UIColor.cyanColor()
return v
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44.0
}
TableView
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- 之前的那版,剛發布,馬上就有朋友給出了寶貴意見。不得不說,與人分享是一件令人高興的事。^-^ 這不今天得空,就將原...
- 源碼地址:https://github.com/maladoufupi/TableViewNestingTable...
- 最近一直使用Storyboard, 遇到很多問題, 當Storyboard用順手之后, 會越用越愛. 使用Stor...
- 在UITableView的Cell里嵌套使用CollectionView場景里,如果在點擊CollectionVi...