zoukankan      html  css  js  c++  java
  • UITabelView 介绍

    1、TableView 样式
    @property (nonatomic, readonly) UITableViewStyle  style;
     
    平铺模式:sectionHeader和sectionFooter会悬停,有sectionIndex,分隔线
    分组模式:heightForHeaderInSection和heightForFooterInSection回调设置0不会起作用,改成0.001f
     
    2、背景
    @property(nonatomic, readwrite, retain) UIView *backgroundView NS_AVAILABLE_IOS(3_2);
    @property(nonatomic,copy)  UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
     
    设置tableView的背景颜色要考虑backgroundView。在plan模式下backgroundView为nil,group模式在iOS6上是有值的。所以不想要backgroundView,最好设置为nil。
     
    3、表头和表尾
    @property(nonatomic,retain) UIView *tableHeaderView;                            
    @property(nonatomic,retain) UIView *tableFooterView;  
     
    表头和表尾都会跟随tableView滑动,表头一般多用来添加SearchBar,
     
    4、分割线
    @property(nonatomic)           UITableViewCellSeparatorStyle separatorStyle;         
    @property(nonatomic,retain) UIColor *separatorColor;
    @property (nonatomic)          UIEdgeInsets   separatorInset NS_AVAILABLE_IOS(7_0)
     
    1)在plan模式下,即使没有cell分割线依然显示,所以一般在plan模式下不使用系统的分割线,将separatorStyle设置为UITableViewCellSeparatorStyleNone,然后自己在cell里添加分割线,
    分割线的添加方法:1、drawRect绘制 2、在contentView中添加view 推荐第二种方法,尽量不免在cell中绘制会导致刷新比较慢
    2)在group模式下,iOS7以后可以考虑使用系统分割线,分割线颜色和偏移都可以设置
     
    5、sectionHeader、sectionFooter、cell高度
    @property (nonatomic)          CGFloat                    rowHeight; 
    @property (nonatomic)          CGFloat                    sectionHeaderHeight; 
    @property (nonatomic)          CGFloat                    sectionFooterHeight; 
     
    如果高度是固定,就直接赋值,尽可能的减少UITableViewDelegate回调获取高度
     
    iOS7之后提供了预估高度提高性能
    @property (nonatomic) CGFloat  estimatedRowHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic) CGFloat  estimatedSectionHeaderHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic) CGFloat  estimatedSectionFooterHeight NS_AVAILABLE_IOS(7_0);
     
    6、sectionIndex 右边索引条
    @property(nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;                                        
    @property(nonatomic, retain) UIColor *sectionIndexColor NS_AVAILABLE_IOS(6_0)         
    @property(nonatomic, retain) UIColor *sectionIndexBackgroundColor NS_AVAILABLE_IOS(7_0)
    @property(nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor NS_AVAILABLE_IOS(6_0)
     
    共有四个属性值,用来设置索引字体颜色和背景颜色,由于试用SDK不同,所以在试用时调用respondsToSelector判断方法存在
     
    7、indexPath和cell之间的转换
    - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell; 
    - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
     
    8、获取可见区域cell
    - (NSArray *)visibleCells;
    - (NSArray *)indexPathsForVisibleRows;
     
    9、UITableViewCell 使用
    1)nib方式使用:
    UINib *nib = [UINib nibWithNibName:@"WXCartCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"WXCartCellID"];
    2)class方式使用
    [self.tableView registerClass:[WXCartCell class] forCellReuseIdentifier:@"WXCartCellID"];
     
    在cellForRowAtIndexPath中复用cell
    WXCartCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WXCartCellID"];
     
    10、让sectionHeaderView 不悬停

    #pragma mark - UIScrollViewDelegate
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGPoint p = scrollView.contentOffset;
       
        CGFloat height = 20;     // sectionHeader height
       
        if (p.y <= height && p.y >= 0) {
            self.tableView.contentInset = UIEdgeInsetsMake(-p.y, 0, 0, 0);
        } else if (p.y >= height) {
            self.tableView.contentInset = UIEdgeInsetsMake(-height, 0, 0, 0);
        }

    }
  • 相关阅读:
    evernote100个做笔记的好方法
    平衡二叉树的调整模版
    晨间日记的奇迹
    hdu 2952 Counting Sheep
    hdu 1535 Invitation Cards
    poj 3259 Wormholes(spfa)
    poj 2263 Heavy Cargo(floyd)
    poj 3268 Silver Cow Party(SPFA)
    hdu 1690 Bus System
    hdu 3631 Shortest Path(Floyd)
  • 原文地址:https://www.cnblogs.com/shuleihen/p/4906911.html
Copyright © 2011-2022 走看看