您的位置:首页 > 产品设计 > UI/UE

UITableViewDataSource

2015-08-26 08:46 393 查看
UITableViewDataSource
关于UITableView的一些相关的属性和方法,以及一些代理方法的使用.
说到UItableView的一个代理是:UITableViewDataSource返回cell的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *
nonnull)
tableView


知道现在的cell是哪一个.即得到当前的cell的标签,然后通过标签来做其他的事情

-
(UITableViewCell *
nonnull)tableView:(UITableView *
nonnull)
tableView
cellForRowAtIndexPath:(NSIndexPath *
nonnull)[code]indexPath
[/code]

在section里现在的row的序号
-
(NSInteger)tableView:(UITableView *
nonnull)tableView
numberOfRowsInSection:(NSInteger)
section
[/code]

显示右边的导航标题- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView当点击右边的标题的时候,就可以直接的跳转到指定的title处,不论你点的是什么,直接跳转返回值处
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString
*)title atIndex:(NSInteger)index根据section来设置titleHeader- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section根据section来设置titleFooter- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section根据点击的编辑按钮,来执行相应的处理- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
在可以编辑之前必须要把tableView的setEditing设置成YES.
代码如下:[tableView
setEditing:YES];
在代理方法里判断editingStyle来执行相对应的处理.可以根据indexPath来设置是否可以被编辑- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
*)indexPath是否可以移动cell,可以根据indexPath来判断- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath
*)indexPath
但是,要与下面的方法结合使用:- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath
*)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
在移动的时候,要注以的是,数据先行,视图后行.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: