ios TableView那些事2(Swift 二) 初见TableView Grouped
2014-11-28 00:27
507 查看
今天让我来创建个简单的Grouped
一
import UIKit
class ViewController: UITableViewController {
let dataScoureArray:[String] = ["A","B","C","D","E","F","G","H"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
//cell Number
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return dataScoureArray.count;
}
//section Number
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
//creat Cell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"cell");
cell.textLabel.text = dataScoureArray[indexPath.row]
return cell;
}
//set Footer Height
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 20;
}
//set Header Height
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20;
}
//set Header Title
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Hello"
}
//set Footer Title
override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "World"
}
//set Cell Row Height
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50;
}
//cell DidSelectAction
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
(二)在实际中我们要定制自己的tableview head 或footer
// 在tableview 的headView 上添加个view 其实你可以在这个view 加很多组件 在添加在HeadView
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
var view:UIView = UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20));
view.backgroundColor = UIColor.yellowColor();
return view;
}
//在footerView 添加个button
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?{
let myButton:UIButton = UIButton(frame: CGRectMake(0, 0, self.view.frame.size.width, 20));
myButton.setTitle("I am a Button", forState: UIControlState.Normal);
myButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal);
myButton.backgroundColor = UIColor.greenColor();
return myButton;
}
一
import UIKit
class ViewController: UITableViewController {
let dataScoureArray:[String] = ["A","B","C","D","E","F","G","H"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
//cell Number
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return dataScoureArray.count;
}
//section Number
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
//creat Cell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"cell");
cell.textLabel.text = dataScoureArray[indexPath.row]
return cell;
}
//set Footer Height
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 20;
}
//set Header Height
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20;
}
//set Header Title
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Hello"
}
//set Footer Title
override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "World"
}
//set Cell Row Height
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50;
}
//cell DidSelectAction
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
(二)在实际中我们要定制自己的tableview head 或footer
// 在tableview 的headView 上添加个view 其实你可以在这个view 加很多组件 在添加在HeadView
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
var view:UIView = UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20));
view.backgroundColor = UIColor.yellowColor();
return view;
}
//在footerView 添加个button
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?{
let myButton:UIButton = UIButton(frame: CGRectMake(0, 0, self.view.frame.size.width, 20));
myButton.setTitle("I am a Button", forState: UIControlState.Normal);
myButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal);
myButton.backgroundColor = UIColor.greenColor();
return myButton;
}
相关文章推荐
- ios TableView那些事2(Swift 一) 初见TableView
- IOS tableview 消除 分割线短 15 像素 ios8方法 swift版
- iOS.swift 如何设置tableview禁止上下滚动
- iOS开发之tableHeaderView的那些坑
- ios tableView那些事
- IOS swift 自定义Tableview cell
- ios TableView那些事(二十 九)UITableViewController 粘合性
- ios swift开发中,使用键盘,tableview根据键盘调整高度
- ios 官网文档翻译—Create a Table View(swift)
- Swift iOS tableView static cell动态计算高度
- ios TableView那些事3(Swift 三) TableView 的删除操作
- Swift 解决IOS开发中TableView中编辑UITextField时键盘遮挡输入框的情况
- IOS(swift)-scrollView(tableView) ·图片加载逻辑的优化
- ios swift tableview
- iOS swift 自定义tableView不显示cell
- iOS - Swift 判断tableView现在是否在最底部
- Swift iOS tableView static cell动态计算高度
- IOS Apps 开发(Swift)(8)——Create a Table View
- iOS开发swift中tableView的条目点击的背景和文字颜色
- iOS项目开发实战——Swift实现多个TableView的侧滑与切换