1、之前的做法:
删自带的ViewController
拖拽一个TableViewController,再Enbedin 一个NavigationController
设置相关。
2、现在的做法:
删自带的ViewController
直接拖入一个NavigationController
这个拖入的NavigationController自带一个TableViewController
![](https://app.yinxiang.com/shard/s41/res/a8455463-ef25-4595-9f1b-c15dc165b622/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8810.32.37.png)
还要做的事情:
1、加程序运行起来开始箭头
![](https://app.yinxiang.com/shard/s41/res/5251c194-c09f-45b1-a117-d06ff1457919/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8810.34.39.png)
2、Cell标识
![](https://app.yinxiang.com/shard/s41/res/8e0a32d4-40f2-40b7-812b-b2c95b905b57/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8810.35.58.png)
3、删掉自带ViewController.h.m 。换成TableViewController类,继承自UITableViewController。
4、storyboard中的页面和代码进行关联。
![](https://app.yinxiang.com/shard/s41/res/42031791-9766-4b2e-89e0-2b29dd22dd1c/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8810.39.55.png)
下一步
创建一个类来描述“人”,Person类,有 都是字符串的name、phoneNumber属性。
在TableViewController中准备好数据源数组。声明并初始化一个persons数组。
打开注释的
self
.
navigationItem
.
rightBarButtonItem
=
self
.
editButtonItem
;
使得出现“Edit”。
创建一个Person对象。
![](https://app.yinxiang.com/shard/s41/res/cfe70ae6-8355-4103-8451-40c0909c1336/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8811.31.56.png)
#pragma mark - Table view data source
- ( NSInteger )tableView:( UITableView *)tableView numberOfRowsInSection:( NSInteger )section {
return self . persons . count ; // 行数等于数据源数组元素个数
}
- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier : @"Cell" forIndexPath :indexPath];
Person *person = self . persons [indexPath. row ];
cell. textLabel . text = person. name ;
cell. detailTextLabel . text = person. phoneNumber ; // 注意拖拽出来的 detailTextLabel ,需要在 storyboard 中设置一下。
return cell;
- ( NSInteger )tableView:( UITableView *)tableView numberOfRowsInSection:( NSInteger )section {
return self . persons . count ; // 行数等于数据源数组元素个数
}
- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier : @"Cell" forIndexPath :indexPath];
Person *person = self . persons [indexPath. row ];
cell. textLabel . text = person. name ;
cell. detailTextLabel . text = person. phoneNumber ; // 注意拖拽出来的 detailTextLabel ,需要在 storyboard 中设置一下。
return cell;
}
![](https://app.yinxiang.com/shard/s41/res/5e830ab7-9692-4078-97f8-2572953b640f/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8811.38.56.png)
![](https://app.yinxiang.com/shard/s41/res/db8bc202-5275-4a17-a39e-da3799c7bbba/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8811.41.45.png)
改下title。
![](https://app.yinxiang.com/shard/s41/res/f1764760-3f68-42a4-a18d-414142c2480f/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-09-11%20%E4%B8%8A%E5%8D%8811.40.22.png)