tableView 一些零散的属性和方法

一些零散的属性和方法

    // 取得选中的那行
   NSIndexPath *path = [self.tableView indexPathForSelectedRow];

  // 每一行cell的高度
    self.tableView.rowHeight = 50;
  // 每一组头部控件的高度
    self.tableView.sectionHeaderHeight = 44;

 // 设置footerView
  MJTgFooterView *footer = [MJTgFooterView footerView];

  footer.delegate = self;

  self.tableView.tableFooterView = footer;

  self.tableView.tableHeaderView


   //表格的设置
  // 去除分割线
    self.tableView.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.allowsSelection = NO; // 不允许选中

    自动滚动表格到最后一行
    NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.messageFrames.count - 1 inSection:0];
    [self.tableView scrollToRowAtIndexPath:lastPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

   封装好的从xib加载cell的方法(自己写的)
  + (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"tg";
    MJTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        // 从xib中加载cell
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MJTgCell" owner:nil options:nil] lastObject];
    }
    return cell;
     }



   关于数据源刷新

    告诉tableView重新加载模型数据
     // reloadData : tableView会向数据源重新请求数据
     // 重新调用数据源的相应方法取得数据
    // 重新调用数据源的tableView:numberOfRowsInSection:获得行数
    // 重新调用数据源的tableView:cellForRowAtIndexPath:得知每一行显示怎样的cell
    // 全部刷新[self.tableView reloadData];
    // 局部刷新
    NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];
    [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom];

   带动画效果的组刷新

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    MyHeaderFooterView *headerView = [MyHeaderFooterView headerViewWithTableView:tableView];

    headerView.groupsModel = _dataArray[section];

    headerView.tag = section;

    NSLog(@"%ld",headerView.tag);

    headerView.delegate = self;

    return headerView;
}

- (void)MyHeaderFooterViewDidClickedWithHeaderView:(MyHeaderFooterView *)headerView
{
    //[self.tableView reloadData];

        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:headerView.tag] withRowAnimation:UITableViewRowAnimationAutomatic];

     }



  //局部section刷新

    NSIndexSet * nd=[[NSIndexSet alloc]initWithIndex:1];//刷新第二个section

    [tview reloadSections:nd withRowAnimation:UITableViewRowAnimationAutomatic];

    //局部cell刷新

    NSIndexPath *te=[NSIndexPath indexPathForRow:2 inSection:0];//刷新第一个section的第二行

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:te,nil] withRowAnimation:UITableViewRowAnimationMiddle];

    //注册cell类
    //[MyTableViewCell class]  cell的集合类
       [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"iden"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    static NSString *iden = @"iden";
//    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
//    if (cell == nil) {
//        cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
//    }
//    BookModel *model = _dataArray[indexPath.row];
//    cell.titleLabel.text     = model.title;
//    cell.detailLabel.text    = model.detail;
//    cell.priceLabel.text     = model.price;
//    cell.iconImageView.image = [UIImage imageNamed:model.icon];
//    return cell;

    //使用集合类
    //从复用池里面找带有iden标识的cell,如果复用池里面没有,系统会自动创建,不用我们管理
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"iden" forIndexPath:indexPath];

    BookModel *model = _dataArray[indexPath.row];
    cell.titleLabel.text = model.title;
    cell.detailLabel.text = model.detail;
    cell.priceLabel.text = model.price;
    cell.iconImageView.image = [UIImage imageNamed:model.icon];
    return cell;

}

        让当前的cell带有动画效果的取消选中时的深背景色

        [tableView deselectRowAtIndexPath:indexPath animated:YES];

 

posted @ 2015-12-11 12:45  谢涵..Fting!  阅读(173)  评论(0编辑  收藏  举报