源码如下:
import UIKit
class TFNetImageViewController: TFBaseViewController, UITableViewDataSource, UITableViewDelegate{
var TFTableView:UITableView!
var itemString = ["姓名","账号","爱好","职业","年薪"]
override func viewDidLoad() {
super.viewDidLoad()
self.setTopNavBarTitle("个人信息")
self.setTopNavBackButton()
self.view.backgroundColor = UIColor.lightGrayColor()
self.creatTable()
}
func creatTable(){
TFTableView = UITableView(frame: CGRectMake(0, 64, AppWidth, AppHeight - 64),style:UITableViewStyle.Grouped);
TFTableView.delegate = self;
TFTableView.dataSource = self;
self.view.addSubview(TFTableView);
}
//MARK: UITableViewDataSource
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2;
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0){
return 1;
}else{
return 5;
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
if(indexPath.section == 0){
return 80;
}else{
return 55;
}
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 10;
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let identifier="identtifier";
var cell=tableView.dequeueReusableCellWithIdentifier(identifier);
if(cell == nil){
cell=UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: identifier);
}
if(indexPath.section == 0){
cell?.textLabel?.text="头像";
}else{
cell?.textLabel?.text=itemString[indexPath.row];
}
cell?.accessoryType=UITableViewCellAccessoryType.DisclosureIndicator;
return cell!;
}
//MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true);
}
}