【UIKit】UITableView 7 常用属性

UITableView的常用属性

   以上图片转自http://blog.csdn.net/totogo2010/article/details/7642908

以上图片转自http://blog.csdn.net/totogo2010/article/details/7642908

1.设置Section的数量

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
 return TitleData;
}

 

2.设置每个section显示的Title

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
 return TitleName;
}

 

3.设置有多少个Section,默认为1,可以不设置

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 return 2;
}

 

4.返回一个分区内有多少行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 30; }

 

5.清除Label的白色

  cell.textLabel.backgroundColor = [UIColor clearColor];

 

6.设置默认的背景颜色

        UIView *bg = [[UIView alloc] init];
        bg.backgroundColor = [UIColor grayColor];
        cell.backgroundView = bg;

 

7.设置被选中时的背景颜色

 // 设置被选中时的背景颜色
        UIView *bgSelected = [[UIView alloc] init];
        bgSelected.backgroundColor = [UIColor redColor];
        cell.selectedBackgroundView = bgSelected;

 

8.设置分隔线样式

// 设置分隔线样式:none,没有
    //tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

 

9.设置分隔线颜色

    // 设置分隔线颜色
    tableView.separatorColor = [UIColor redColor];

 

10.设置允不允许选中

 tableView.allowsSelection = NO;

 

11.返回选中的所有行,数组

// 返回选中的所有行
    [tableView indexPathsForSelectedRows];

 

12.返回可见的所有行,数组

   // 返回可见的所有行
    [tableView indexPathsForVisibleRows];

 

13.设置行选中事件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

 

14

1:常用属性:

①:@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle; 默认为UITableViewCellSeparatorStyleSingleLine

②:@property(nonatomic,retain) UIColor *separatorColor; 默认为:the standard separator gray

③:@property(nonatomic,retain) UIView *tableHeaderView; 头部视图

④:@property(nonatomic,retain) UIView *tableFooterView; 尾部视图

⑤:@property(nonatomic) CGFloat rowHeight; // 单元格高度

⑥:@property(nonatomic) CGFloat sectionHeaderHeight; // 头部行高

⑦:@property(nonatomic) CGFloat sectionFooterHeight; //尾部行高

⑧:@property(nonatomic,readwrite,retain) UIView *backgroundViewNS_AVAILABLE_IOS(3_2);
⑨:@property(nonatomic,readonly) UITableViewStyle style;

2:常用方法:

①:- (void)reloadData; // reloads everything from scratch. redisplays visible rows. because we only keep info about visible rows, this is cheap. will adjust offset if table shrinks 刷新单元格的数据

②:- (void)reloadSectionIndexTitlesNS_AVAILABLE_IOS(3_0); // reloads the index bar.

③:- (NSInteger)numberOfSections; //返回节的数量

④:- (NSInteger)numberOfRowsInSection:(NSInteger)section;//返回每个节的单元格的数量

⑤:- (CGRect)rectForSection:(NSInteger)section; // includes header, footer and all rows

⑥:- (CGRect)rectForHeaderInSection:(NSInteger)section;

⑦:- (CGRect)rectForFooterInSection:(NSInteger)section;

⑧:- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;

⑨:- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point; // returns nil if point is outside table

⑩:- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell; //返回指定单元格的NSIndexPath实例

十一:- (NSArray *)indexPathsForRowsInRect:(CGRect)rect; //返回指定范围的NSIndexPath实例数组

十二:- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath; // returns nil if cell is not visible or index path is out of range //返回指定NSIndexPath实例的单元格实例

十三:- (NSArray *)visibleCells; //返回可见的单元格的数组

十四- (NSArray *)indexPathsForVisibleRows; //返回可见单元格的NSIndexPath实例数组

十五:- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)sectionNS_AVAILABLE_IOS(6_0);

十六:- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)sectionNS_AVAILABLE_IOS(6_0);

十七:- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated; //滑动到指定的位置,并且可以加上动画效果

十八:- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

 

posted @ 2014-04-17 21:10  太过于漂流  阅读(343)  评论(0编辑  收藏  举报