通讯录

2016-11-08  本文已影响0人  陆小琪

importUIKit

classViewController:UIViewController{

/*

C:程耀冬程勇山程思源

D:董欣雨董一涵邓安平邓丁瑞邓笑梅邓梅芳邓晴紫邓紫悦

F:方一心方雪冰方华勇方子义方忠田方开强

G:高志山高尚淑高伶映高玟富高心毓

*/

letkeys = ["C","D","F","G"]

letnames = [["程耀冬","程勇山","程思源"],["董欣雨","董一涵","邓安平","邓丁瑞","邓笑梅","邓梅芳","邓晴紫","邓紫悦"],["方一心","方雪冰","方华勇","方子义","方忠田","方开强"],["高志山","高尚淑","高伶映","高玟富","高心毓"]]

overridefuncviewDidLoad() {

super.viewDidLoad()

lettableView =UITableView(frame:UIScreen.mainScreen().bounds, style: .Plain)

tableView.delegate=self

tableView.dataSource=self

view.addSubview(tableView)

tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier:"cell")

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

extensionViewController:UITableViewDelegate,UITableViewDataSource{

//返回每个分区行数

functableView(tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

returnnames[section].count

}

//返回单元格

functableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) ->UITableViewCell{

letcell = tableView.dequeueReusableCellWithIdentifier("cell")

//获取到这个分区的所有数据

letvalues =names[indexPath.section]

//拿到当前行的数据

letstr = values[indexPath.row]

cell?.textLabel?!.text= str

returncellas!UITableViewCell!

}

//返回分区数

funcnumberOfSectionsInTableView(tableView:UITableView) ->Int{

returnkeys.count

}

//分区标题

functableView(tableView:UITableView, titleForHeaderInSection section:Int) ->String? {

returnkeys[section]

}

//分区索引

funcsectionIndexTitlesForTableView(tableView:UITableView) -> [String]? {

returnkeys

}

}

上一篇 下一篇

猜你喜欢

热点阅读