样例功能如下:
效果图如下:
实现步骤:
1,在storyboard中拖入一个新的ViewController用做详情页面,同时创建一个继承ViewController的新类DetailViewController。并将其与storyboard中新建的详情页面进行视图与控制器的绑定。
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import
UIKit
class
ViewController
:
UIViewController
,
UITableViewDelegate
UITableViewDataSource
{
var
ctrlnames:[
String
] = [
"任务1"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"任务2"
"任务3"
]
tableView:
UITableView
?
override
func
loadView() {
super
.loadView()
}
viewDidLoad() {
.viewDidLoad()
//创建表视图
self
.tableView =
(frame:
.view.frame,style:
UITableViewStyle
.
Plain
)
.tableView!.delegate =
self
.tableView!.dataSource =
self
//创建一个重用的单元格
.tableView!.registerClass(
UITableViewCell
.
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,forCellReuseIdentifier:
"cell1"
)
.view.addSubview(
.tableView!)
}
//在本例中,只有一个分区
numberOfSectionsInTableView(tableView:
) ->
Int
{
return
1;
}
//返回表格行数(也就是返回控件数)
tableView(tableView:
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,numberOfRowsInSection section:
{
return
.ctrlnames.count
}
NSIndexPath
)
->
UITableViewCell
{
let
identify:
=
"cell1"
//同一形式的单元格重复使用,在声明时已注册
cell = tableView.dequeueReusableCellWithIdentifier(identify,
forIndexPath: indexPath)
as
UITableViewCell
cell.accessoryType =
UITableViewCellAccessoryType
disclosureIndicator
cell.textLabel?.text =
.ctrlnames[indexPath.row]
cell
}
// UITableViewDelegate 方法,处理列表项的选中事件
)
{
itemString =
.ctrlnames[indexPath.row]
.performSegueWithIdentifier(
"ShowDetailView"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,sender: itemString)
}
prepareForSegue(segue:
UIStoryboardSegue
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,sender:
AnyObject
?) {
if
segue.identifier ==
{
controller = segue.destinationViewController
as
!
DetailViewController
controller.itemString = sender
?
String
}
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
}
|
DetailViewController
itemString:
?
@IBOutlet
weak
textField:
UITextField
!
viewDidLoad() {
.viewDidLoad()
textField.text = itemString
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
原文出自:
www.hangge.com
转载请保留原文链接:
http://www.hangge.com/blog/cache/detail_720.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。 相关推荐 |