• UITableView 委托方法总结


     
    总结: UITableViewDelegate
      row:     heightForRow
      header:    heightForHeader
             viewForHeader
             titleForHeader (viewForHeader 相冲突)
      
      title:     heightForTitle
             viewForTitle
             titleForTitle (viewForTitle 相冲突)
     
     总结: UITableViewDatasource
      numberOfRowsInSection      (required)
          cellForRow          (required)

    UITableView应用(一)UITableViewDelegate方法总结

     
     
    1.定义每个UITableView中的cell的行高
     

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

    // indexPath.section,根据分组进行更精确的配置

    return 90.0;

    }

     
    2.设置UITableView每个分组的Header的Title
     

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return [_arrayType objectAtIndex:section];

    }

     
    3.设置UITableView分组Header的高
     

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 30.0;

    }

     
    4.设置UITableView自定义的Header
     

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    // 自定义的Header

    ViewForCellHeader *headerView=[[[ViewForCellHeader alloc] init] autorelease];

    headerView.strSectionName=[_arrayType objectAtIndex:section];

    return [headerView view];

    }

     

    注意:2与4是互斥的。

     
    同理原理,我们分别也对Footer进行设置。
     
    5.设置UITableView每个分组的Footer的Title
     

    - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

    return [_arrayType objectAtIndex:section];

    }

     
    6.设置UITableView分组Footer的高
     

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    // indexPath.section,根据分组进行更精确的配置

    return 30.0;

    }

     
    7.设置UITableView自定义的Footer
     

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    // 自定义的Footer

    ViewForCellHeader *headerView=[[[ViewForCellHeader alloc] init] autorelease];

    headerView.strSectionName=[_arrayType objectAtIndex:section];

    return [headerView view];

    }

     
    8.设置UITableView每个分组的Footer的Title
     

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return [_arrayType objectAtIndex:section];

    }

    UITableView应用(二)UITableViewDataSource 方法总结


    NSMutableArray *_arrayType;// 分组

     
    1.返回分组数

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [_arrayType count];

    }


    2.根据分组,返回每个分组的行数
     

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSString *curType=[_arrayType objectAtIndex:section];

    return [[_dictData objectForKey:curType] count];

    }

     
    3.根据分组,返回每个cell
     

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSUInteger section = [indexPath section];

    NSUInteger row = [indexPath row];

    NSString *key=[_arrayType objectAtIndex:section];

    NSMutableArray *arrValues=[_dictData objectForKey:key];

    static NSString *CellIdentifier = @"WTVChannelCell";

    // 自定义cell

    WTVChannelCell *cell = (WTVChannelCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil){

    cell = [[[WTVChannelCell alloc] initWithStyle:UITableViewCellSelectionStyleGray reuseIdentifier:CellIdentifier] autorelease];

    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"WTVChannelCell" owner:nil options:nil];

    cell = [array objectAtIndex:0];

    }

    cell.dictChannelData=[arrValues objectAtIndex:row];

    [cell refreshCellData];

    return cell;

    }

  • 相关阅读:
    2018年12月9日 带小苗苗打针 函数2 前向引用 函数即变量
    2018年12月8日 函数变量与递归
    2018年12月7日 字符串格式化2 format与函数1
    2018年12月6日 字符串拼接 %的用法
    2018年11月29日 16点50分 小苗苗出生了
    2018年11月27日 分类与集合
    2018年11月26日 练习3
    2018年11月25日 练习2
    2018年11月24日 周末学习1 字典2
    2018年11月22日 字典 E18灯翼平整度 D&G is SB
  • 原文地址:https://www.cnblogs.com/apem/p/3977396.html
Copyright © 2020-2023  润新知