UITableView
header,footer,section,section header,section footer
plain style, grouped style
cell type
99%情况下TableView都是和TableViewController一起使用
拖到storyboard中自带的view就是UITableView
可以自定义UIViewTableController的子类。用于初始化
属性:
datasource id<TableViewDataSource> 数据是什么 what to display
delegate 如何显示 how display
*如果是拖拽出tableviewcontroller会自动配置datasource,delegate,自动关联。如果是单独拖拽出tableview到其他的controller或者view中,则要自己手动配置
tableViewController.tableView
配置tableview:
content:dynamic,static 动态从数据库读取还是不需要加载数据库的
prototype cell[cell原型]: plain[普通],grouped [成组,集合]
subtitle,detail[可以添加图片,或者打勾等]
重要!: 配置Cell identifier 用于在程序中获取identifier,并复制使用。与控制器中的segue命名identifier一样,用来跳转获取标识。
UITableViewDataSource:
1.how many sections 多少个组
2.how many rows in each section 每个组多少行
3.give me a UITableViewCell [identifier] 给一个cell视图,显示row
// 从数据库中动态的
-(UITableViewCell *)tableView:(UITableView *)sender
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 2 things todo here
// get a cell to use (instance of UITableViewCell) 创建
UITableViewCell *cell;
cell = [self.tableView dequeueReusableCellWithIndentifier:@"Flickr Photo Cell"
forIndexPath:indexPath];
// set @propertys on the cell to prepare it to display 配置
cell.textLabel.text = [self getMyTitleForRow:indexPath.row inSection:indexPath.section;
//cell.subTitle,cell.detailTitle,cell.image? 等等
];
}
indexPath 是一个索引对象,描述section和section中的行 row
// in a static table ,u don't need to implement this method. u can if u want to ignore what's in the storyboard.
// static 的不用设置,因为已经在storyboard中设置好了
section和对应row的数量。如果不实现它,默认是1section
-(NSInteger) numberOfSectionsInTableView:(UITableView *)sender;
-(NSInteger)tableView:(UITableView *)sender numberOfRowsInSections:(NSInteger)section;
~~~~如果是static table,以上的三个函数都不需要实现~~~
UITableViewDelegate:
表示如何显示,how
-(void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
// 单击 i 按钮
-(void)table:(UITableView *)sender accessoryButtonTappedForRowIndexPath:(NSIndexPath *)indexPath
{
}
UITableView Segue
UITableViewController中有
// 这个是当跳转前调用,设置数据源等给新的界面。
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
// segue.destinationController
// get section = indexPath.section, row = indexPath.row
}
UITableViewController.refreshControl beginRefreshing,endRefreshing. 加载的indicator
!!这个可以在用户下拉table的时候显示这个loading,然后发送一个事件去更新数据
Refreshing:Enabled attribute inspector属性面板中设置,会在storyboard中添加一个新的元件,把它关联到storyboard中,输出Action。
如果数据模型更改了,可以调用
-(void)reloadData; // 这个基本上是很多或者全部数据都更新了,如果是小部分,可以:
-(void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animationStyle;
其他方法:
继承scrollview的所有方法
设置header,footer,。。