CS193p 斯坦福IOS开发 2011 (九)

这节课讲了如何展示动态数据列表/固定数据列表

UITableView

  • 一维表
  • UIScrollView子类
  • 可以是动态的也可以是静态的
  • 可以通过datasource协议和代理协议进行很多定制
  • 在展示大型数据的时候也非常高效

展示多维表

使用包含多个MVC的UINavigationController

UITableView的类型

  • plain或者grouped


    CS193p 斯坦福IOS开发 2011 (九)_第1张图片
    Screen Shot 2019-02-14 at 11.33.25 AM.png
CS193p 斯坦福IOS开发 2011 (九)_第2张图片
Screen Shot 2019-02-14 at 11.38.09 AM.png
CS193p 斯坦福IOS开发 2011 (九)_第3张图片
Screen Shot 2019-02-14 at 11.38.01 AM.png
  • 静态或者动态
  • 分为sections或者不分


    CS193p 斯坦福IOS开发 2011 (九)_第4张图片
    Screen Shot 2019-02-14 at 11.38.19 AM.png
  • 表内每一行的展示形式可以定制


    CS193p 斯坦福IOS开发 2011 (九)_第5张图片
    Screen Shot 2019-02-14 at 11.38.19 AM.png

UITableView属性

  • delegate: The delegate is used to control how the table is displayed.
  • dataSource: The dataSource provides the data what is displayed inside the cells.
    默认情况下UITableViewController被设置为UITableView的delegate和dataSource

delegate控制UITableView怎么展示,dataSource 控制UITableView展示什么

多少row多少个section

- (NSInteger)numberOfSectionsInTableView:(UITableView *)sender;
- (NSInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSInteger)section;

UITableView delegate

  • 选中row
- (void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSIndexPath *)path {
 // go do something based on information
// about my data structure corresponding to indexPath.row in indexPath.section
}
  • 其他delegate 方法

Table View Segue

使用Segue可以在不同Table View之间进行跳转

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
// prepare segue.destinationController to display based on information
// about my data structure corresponding to indexPath.row in indexPath.section }

你可能感兴趣的:(CS193p 斯坦福IOS开发 2011 (九))