美文网首页
TableView 菜鸟容易忘记的细节

TableView 菜鸟容易忘记的细节

作者: 哈么么茶 | 来源:发表于2016-07-25 10:38 被阅读67次

看图


屏幕快照 2016-07-25 下午10.52.59.png

1.最上面动图是TableView的 tableHeaderView,在initWithFrame设置如下:

    _headImageScView = [[KKImageScroller alloc] init];
    _headImageScView.delegate = self;
    _headImageScView.frame = CGRectMake(0, 0, HMScreenW, 210);
  #pragma mark - 先设置大小 再设置为 tableHeaderView
//[_tableView setTableHeaderView:_headImageScView];
    _tableView.tableHeaderView = _headImageScView;

一定先设置大小 再设置为 tableHeaderView,这样不会遮挡第一个cell.

假如是动态头部,每次改变frame后要重新设置一遍 :

_tableView.tableHeaderView = _headImageScView;

这样保证tableHeaderView每次frame都是正确的!

2.热门那个view是所有section的头部,这个如果只设置文字,在以下方法中设置

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

return @"热门推荐";

}

如果需要设置带按钮或者图片的效果,就要自定义一个view继承UITableViewHeaderFooterView,然后在下面方法中返回:

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

    HomeFirstHeaderV *headerView = [HomeFirstHeaderV shareHomeFirstHeaderV:tableView];
    headerView.frame = CGRectMake(0, 5, HMScreenW, 20);

    return  headerView;
}

此头部视图若想循环使用,在自定义的时候添加以下代码

  HomeFirstHeaderV *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ID];

  if (headerView == nil) {
      headerView = [[self alloc] initWithReuseIdentifier:ID];
    }

在以下方法中设置sectionHeader大小,其中return 0.1的时候最小。

  - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
    }

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

      return 30;
  }

最后实现sectionHeader悬停效果,设置UITableViewStyle为UITableViewStylePlain,不要悬停就设置为UITableViewStyleGrouped。

  typedef NS_ENUM(NSInteger, UITableViewStyle) {
        UITableViewStylePlain,          // regular table view
        UITableViewStyleGrouped         // preferences style table view
  };

一个菜鸟的自白。

相关文章

  • TableView 菜鸟容易忘记的细节

    看图 1.最上面动图是TableView的 tableHeaderView,在initWithFrame设置如下:...

  • tableView相关细节

    insert Row或者delete Row的时候要相应的增加和减少代理方法返回的行数。 tableView的se...

  • tableview 使用细节

    1.iOS 终止 sectionHeader 浮动方法 1.为你的自定义header增加两个属性 @prop...

  • tableview 使用细节

    iOS 终止 sectionHeader 浮动方法 1.为你的自定义header增加两个属性 2.重写setFra...

  • 做事与说事

    做事的时候,容易陷入细节,忘记大目标。 说事也就是汇报的时候,容易陷入假大空,所表达的价值容易空话套话,这时应该讲...

  • tableView左右联动

    实现 tableView联动 主要有两个细节(需要创建两个tableView) 1、点击左侧 cell 让右侧 t...

  • 忘记,教育。

    怀特海说:忘记了课堂上所学的一切,剩下的东西才是教育。 知识的细节是很容易忘记的,一旦需要...

  • collectionView tableView的细节处理

    1.设置collectionView的高度1.1为什么要设置高度?collectionView是在tableVie...

  • 容易忘记

    中午,晴给我打电话,说她又忘了带钥匙回来。一听我就有点恼,又忘!开学没几天,已经是第三次忘带钥匙了。 第一次忘带钥...

  • 容易忘记

    忘记是那么的容易 秋风阵阵把鲜花绿叶的养分收走 纷纷落地 一个枯字 天地一片虚无 凛冽和雪花席卷大地 独独忽略了白...

网友评论

      本文标题:TableView 菜鸟容易忘记的细节

      本文链接:https://www.haomeiwen.com/subject/jcpgjttx.html