//
// ViewController.swift
// Demo6
//
// Created by lanou on 16/11/7.
// Copyright (c) 2016年 lanou. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
// let classmateDict = ["F":["方亮","方了"],"G":["郭黄婷","桂程鹏"],"W":["吴镇翦","王梨慧"],"Q":["邱青苗","邱淑贞"],"Z":["钟伟初","周旭凯","周杰"]]
let keys = ["F","G","W","Q","Z"]
let classmateArray:[[String]] = [["方亮","方了"],["郭黄婷","桂程鹏"],["吴彦祖","王梨慧"],["邱青苗","邱淑贞"],["钟伟初","周旭凯","周杰"]]
// let names = ["张三","吴三","李三","陈三"]
override func viewDidLoad() {
super.viewDidLoad()
// Plain分区之间没有间距,Group分区之间有间距
let table = UITableView(frame: view.bounds, style: UITableViewStyle.Plain)
// table.separatorColor = UIColor.blueColor()
// table.separatorStyle = UITableViewCellSeparatorStyle.SingleLineEtched
//提供视图相关操作
table.delegate = self
// 提供数据源代理 (负责提供数据)
table.dataSource = self
view.addSubview(table)
// 给tableView 注册cell,当有cell滑出屏幕时将其存入缓存池,并标识为cell。
// table.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController :UITableViewDelegate,
// 返回分区的行数
UITableViewDataSource{
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return classmateArray[section].count
}
// 返回每个单元格,单元格:UItableViewCell indexPath:
// 第几分区第几行
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
let array = classmateArray[indexPath.section]
let str = array[indexPath.row]
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
cell.textLabel?.text = str
cell.detailTextLabel?.text = "瑟瑟发抖的小人"
cell.imageView?.image = UIImage(named: "box1.png")
return cell
}
//
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return keys.count
}
// 区头标题
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return keys[section]
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! {
return keys
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
return 50
}else if indexPath.section == 1{
return 80
}else{
return 60
}
}
}