tableView视图列表1: titleForHeaderInSection
2014-12-02 14:12
567 查看
这几个方法都是Data Source Methods,就是数据来源的方法。换句话说就是在这里面你得确定数据的来源。
主要涉及的有这几个方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView
*)tableView;
上面这个方法就是让tableView知道他有几个section,默认为1,当你的数据源有两个块时,就是return 2;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
上面这个方法是让tableView知道他每一个块有几个cell,传进来的是一个section的值,就是第几个块。这时你根据section的值来返回这个块有的cell的个数.比如section为0,返回电影的个数,为1,就是电视剧的个数。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
上面这个方法是让tableView知道他每一个cell是怎么样的。注意到传进来的indexPath吗?他就是“坐标”,他表明了cell在第几个块第几个cell,得到的方法为indexPath.section;indexPath.row;然后你根据“块序号”、“行序号”来构造不用的cell.
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
这个是设置每一个块的title,传进来的参数为section;
但是如果把数据写死的话,镔哥觉得不大好。一般我们都通过NSArray来存储数据,比如用movieArray存储电影,用dramaArray存储电视剧,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;这个方法里面你就根据section的值分别返回
[movieArray count],[dramaArray count].这样修改起来也方便。
还有就是TableView Delegate,主要是决定将要选定某个cell及选定某个cell后的操作。与只有一个section的判断不同的是,你还得考虑indexPath.section值来确定你要响应的是哪一个cell的事件。
主要涉及的有这几个方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView
*)tableView;
上面这个方法就是让tableView知道他有几个section,默认为1,当你的数据源有两个块时,就是return 2;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
上面这个方法是让tableView知道他每一个块有几个cell,传进来的是一个section的值,就是第几个块。这时你根据section的值来返回这个块有的cell的个数.比如section为0,返回电影的个数,为1,就是电视剧的个数。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
上面这个方法是让tableView知道他每一个cell是怎么样的。注意到传进来的indexPath吗?他就是“坐标”,他表明了cell在第几个块第几个cell,得到的方法为indexPath.section;indexPath.row;然后你根据“块序号”、“行序号”来构造不用的cell.
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
这个是设置每一个块的title,传进来的参数为section;
但是如果把数据写死的话,镔哥觉得不大好。一般我们都通过NSArray来存储数据,比如用movieArray存储电影,用dramaArray存储电视剧,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;这个方法里面你就根据section的值分别返回
[movieArray count],[dramaArray count].这样修改起来也方便。
还有就是TableView Delegate,主要是决定将要选定某个cell及选定某个cell后的操作。与只有一个section的判断不同的是,你还得考虑indexPath.section值来确定你要响应的是哪一个cell的事件。
相关文章推荐
- ios:改变tableview的titleForHeaderInSection字体颜色设置
- 【iOS】tableView:viewForHeaderInSection: 方法未调用
- QQ好友列表(处理头部控件的点击)viewForHeaderInSection:
- iOS tableview viewForHeaderInSection 自定义
- - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- TableView viewForHeaderInSection 随滚动条滚动 无遮挡
- 折叠表格思路及遇到的问题(tableView:viewForHeaderInSection:的section从1开始,不是从0开始)
- ios开发之--ios11适配:TableView的heightForHeaderInSection设置高度无效/UISearchBar消失
- UITableView的tableHeaderView和viewForHeaderInSection區別
- iOS开发UI— QQ好友列表(处理头部控件的点击)viewForHeaderInSection:
- 如何设置不同组section的的头部高度?tableView heightForHeaderInSection
- 解决tableview下滑隐藏HeaderInSection的问题
- iOS开发:Xcode 7之后viewForHeaderInSection、viewForFooterInSection设置内容不产生效果的解决方法
- ios tableView 的header for section无法加载的问题
- UITableView heightForHeaderInSection遇到的坑
- 自定义viewForHeaderInSection、自定义组头的显示
- viewForHeaderInSection 复用问题
- 简单代码设置titleForHeaderInSection
- 【iOS开发】关于Xcode8后产生的viewForHeaderInSection、viewForFooterInSection设置不产生效果的问题
- UITableView的代理方法viewForHeaderInSection不执行的原因