通过使用静态单元格的列表,我们可以很方便的进行页面布局。下面通过一个“添加任务页面”来进行演示。
效果图如下:

实现步骤:
1,在storyboard中拖入一个TableViewController,同时创建一个对应的类(MyTabelViewController.swift)进行绑定。
2,选择表格,在属性面板中设置Content为Static Cells,Sections设置为2

3,选中第1个Sections,将Rows设置为1,并拖入一个TextFiled到单元格中

4,选中第2个Sections,将Rows设置为2,分别给两个单元格拖入对应的Label和Switch等控件

5,MyTabelViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
class MyTableViewController : UITableViewController {
override func viewDidLoad() {
super .viewDidLoad()
self .title = "添加任务"
//去除尾部多余的空行
self .tableView.tableFooterView = UIView (frame: CGRectZero )
}
override func didReceiveMemoryWarning() {
super .didReceiveMemoryWarning()
}
override func numberOfSectionsInTableView(tableView: UITableView ) -> Int {
return 2
}
override func tableView(tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
if section == 0 {
return 1
} else {
return 2
}
}
} |