标签:
let TAG_LABEL = 1
var data : NSDictionary!
//这一段是从storyboard初始化需要加入这段.......为必须要的
required init(coder aDecoder: NSCoder) {
super.init(coder : aDecoder)
data = NSDictionary(contentsOfURL: NSBundle.mainBundle().URLForResource("data", withExtension: "plist")!) //bundle,用文件初始化一个变量,这个初始化是通过自己写的datasource文件名
self.dataSource = self ;//自己为自己提供数据
self.delegate = self //这个也需要在加载的时候初始化
}
//返回section的个数
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return data.count //这个data是section层面的
}
//特定行获取UITableViewCell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//这个参数cell是tableViewCell指定的reuse id ,这个cell中也有一个TAG设置为1的label,函数Returns a reusable table-view cell object located by its identifier.
var cell: AnyObject! = tableView.dequeueReusableCellWithIdentifier("cell")
var label = cell.viewWithTag(TAG_LABEL) as UILabel
//这里先按section把值存到array里面,在对应把section中的行值转化为string
label.text! = ((data.allValues[indexPath.section]).objectAtIndex(indexPath.row) as String)
return cell as UITableViewCell
}
//seciton头标题
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
return data.allKeys[section] as? String }
//section的中row的个数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (data.allValues[section]).count //对应section的的所有值的行数目
}
//单个cell被选择后的处理事件
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
println("\(data.allValues[indexPath.section].objectAtIndex(indexPath.row)) Clicked ")
}
}
IOS的seciton
标签:
原文地址:http://www.cnblogs.com/KyleRuan/p/4296070.html