iOSTableView的代理函数
1.必须
-(NSInteger)numberOfSectionsInTableView:(UITableView)tableView
{
//返回tableView的分区数
}
-(NSInteger)tableView:(UITableView)tableViewnumberOfRowsInSection:(NSInteger)section
{
//返回每个分数数的行数
}
-(UITableViewCell)tableView:(UITableView)tableViewcellForRowAtIndexPath:(NSIndexPath)indexPath
{
//返回tableView中每行的内容
}
2.编辑(删除,插入等)
-(BOOL)tableView:(UITableView)tableViewcanEditRowAtIndexPath:(NSIndexPath)indexPath
{
//返回是否可以编辑
}
-(UITableViewCellEditingStyle)tableView:(UITableView)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath)indexPath
{
//对当前行数设置编辑模式(删除,插入,不可编辑,多选(|))
}
-(void)tableView:(UITableView)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath)indexPath
{
//真正实现编辑的方法,在这个方法里面修改数据源,刷新
}
-(NSString)tableView:(UITableView)tableViewtitleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath)indexPath
{
//修改删除按钮的文本显示
}
-(void)tableView:(UITableView)tableViewwillBeginEditingRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托,表视图将要被编辑时调用(删除、插入,而不是对cell内容进行编辑)
}
-(void)tableView:(UITableView)tableViewdidEndEditingRowAtIndexPath:(NSIndexPath)indexPath
{
//表视图完成编辑时调用
}
-(BOOL)tableView:(UITableView)tableViewshouldIndentWhileEditingRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托在编辑模式下是否需要对表视图指定行进行缩进,这个方法可以用来去掉move时row前面的空白
}
3.选择(取消选中:在下一行将要被选中后才能取消上一行的选中)
-(void)tableView:(UITableView)tableViewdidSelectRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托指定行被选中
}
-(NSIndexPath)tableView:(UITableView)tableViewwillSelectRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托指定行将被选中,返回值为NSIndexPath是指返回响应行的索引,即可以点击一行而返回另一行的索引,也可以返回nil
}
-(void)tableView:(UITableView)tableViewdidDeselectRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托某行被取消选中
}
-(NSIndexPath)tableView:(UITableView)tableViewwillDeselectRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托指定行将被取消选中
}
4.设置高度
-(CGFloat)tableView:(UITableView)tableViewheightForRowAtIndexPath:(NSIndexPath)indexPath
{
//返回每一行的高度
}
-(CGFloat)tableView:(UITableView)tableViewheightForHeaderInSection:(NSInteger)section
{
//返回每一个section的header的高度
}
-(CGFloat)tableView:(UITableView)tableViewheightForFooterInSection:(NSInteger)section
{
//返回每一个section的footer的高度
}
5.设置header和footer
-(NSString)tableView:(UITableView)tableViewtitleForHeaderInSection:(NSInteger)section
{
//定义每一个section的header的名称
}
-(NSString)tableView:(UITableView)tableViewtitleForFooterInSection:(NSInteger)section
{
//定义每一个section的footer的名称
}
-(UIView)tableView:(UITableView)tableViewviewForHeaderInSection:(NSInteger)section
{
//设置分区的header的视图,可以为任何UIView的子类
}
-(UIView)tableView:(UITableView)tableViewviewForFooterInSection:(NSInteger)section
{
//设置分区的footer的视图
}
-(void)tableView:(UITableView)tableViewwillDisplayHeaderView:(UIView)viewforSection:(NSInteger)section
{
//通知委托将要显示section的header的视图
}
-(void)tableView:(UITableView)tableViewwillDisplayFooterView:(UIView)viewforSection:(NSInteger)section
{
//通知委托将要显示section的footer的视图
}
6.cell的移动
-(BOOL)tableView:(UITableView)tableViewcanMoveRowAtIndexPath:(NSIndexPath)indexPath
{
//是否可以移动
}
-(void)tableView:(UITableView)tableViewmoveRowAtIndexPath:(NSIndexPath)sourceIndexPathtoIndexPath:(NSIndexPath)destinationIndexPath
{
//移动调用的方法,可以在里面设置数据源的一些操作
}
-(NSIndexPath)tableView:(UITableView)tableViewtargetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath)sourceIndexPathtoProposedIndexPath:www.baiyuewang.net(NSIndexPath)proposedDestinationIndexPath
{
//移动的过程中多次调用次方法,返回值是进行移动操作结束后回到的行,如果是当前行,则不论移动到哪一行都会回到当前行
//其中sourceIndexPath是要移动的行
//proposedDestinationIndexPath经过的行
}
-(void)tableView:(UITableView)tableViewdidEndDisplayingCell:(UITableViewCell)cellforRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托指定cell已经移出可视范围
}
-(void)tableView:(UITableView)tableViewdidEndDisplayingHeaderView:(UIView)viewforSection:(NSInteger)section
{
//通知委托指定的section的header已经移出可视范围
}
-(void)tableView:(UITableView)tableViewdidEndDisplayingFooterView:(UIView)viewforSection:(NSInteger)section
{
//通知委托指定的section的footer已经移出可视范围
}
7.索引
-(NSArray)sectionIndexTitlesForTableView:(UITableView)tableView
{
//返回索引的数组
}
-(NSInteger)tableView:(UITableView)tableViewsectionForSectionIndexTitle:(NSString)titleatIndex:(NSInteger)index
{
//点击索引的时候调用该方法
}
8.cell即将显示
-(void)tableView:(UITableView)tableViewwillDisplayCell:(UITableViewCell)cellforRowAtIndexPath:(NSIndexPath)indexPath
{
//cell将要显示时候调用这个方法,可以在这里面修改cell的一些属性,如颜色
}
9.长按菜单
-(BOOL)tableView:(UITableView)tableViewshouldShowMenuForRowAtIndexPath:(NSIndexPath)indexPath
{
//是否显示长按菜单
}
-(BOOL)tableView:(UITableView)tableViewcanPerformAction:(SEL)actionforRowAtIndexPath:(NSIndexPath)indexPathwithSender:(id)sender
{
//弹出选择菜单时会调用这个方法(复制、黏贴、全选、剪切)
}
-(void)tableView:(UITableView)tableViewperformAction:(SEL)actionforRowAtIndexPath:(NSIndexPath)indexPathwithSender:(id)sender
{
//选择菜单项完成之后调用该方法
}
10.高亮显示
-(BOOL)tableView:(UITableView)tableViewshouldHighlightRowAtIndexPath:(NSIndexPath)indexPath
{
//选中行是否高亮
}
-(void)tableView:(UITableView)tableViewdidHighlightRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托指定行被高亮显示
}
-(void)tableView:(UITableView)tableViewdidUnhighlightRowAtIndexPath:(NSIndexPath)indexPath
{
//通知委托表视图的指定行不再高亮显示,一般是在点击其他行的时候调用
}
|
|