表视图(UITableView)的一些常用方法和属性

本文详细介绍了UITableView的常用属性及方法,包括设置样式、颜色、视图等属性的方法,以及 reloadData、scrollToRowAtIndexPath 等操作数据和滚动视图的方法。通过本文,读者可以快速掌握 UITableView 的使用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

		                       表视图(UITableView)的一些常用方法和属性:
					
      	一:常用属性:

          1:@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;     // 默认为UITableViewCellSeparatorStyleSingleLine
          2:@property(nonatomic,retain) UIColor *separatorColor;                   // 默认为:the standard separator gray
          3:@property(nonatomic,retain) UIView *tableHeaderView;                   // 头部视图
          4:@property(nonatomic,retain) UIView *tableFooterView;                   // 尾部视图
          5:@property(nonatomic) CGFloat rowHeight;                                // 单元格高度
          6:@property(nonatomic) CGFloat sectionHeaderHeight;                      // 头部行高
          7:@property(nonatomic) CGFloat sectionFooterHeight;    				   // 尾部行高
          8:@property(nonatomic,readwrite,retain) UIView *backgroundViewNS_AVAILABLE_IOS(3_2); 
          9:@property(nonatomic,readonly) UITableViewStyle style;

       二:常用方法:

          1:- (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  刷新单元格的数据
          2:- (void)reloadSectionIndexTitlesNS_AVAILABLE_IOS(3_0);  // reloads the index bar. 
          3:- (NSInteger)numberOfSections;   //返回节的数量
          4:- (NSInteger)numberOfRowsInSection:(NSInteger)section;  //返回每个节的单元格的数量
          5:- (CGRect)rectForSection:(NSInteger)section;            // includes header, footer and all rows
          6:- (CGRect)rectForHeaderInSection:(NSInteger)section;
          7:- (CGRect)rectForFooterInSection:(NSInteger)section;
          8:- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
          9:- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;  // returns nil if point is outside table
          10:- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;   //返回指定单元格的NSIndexPath实例
          11:- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;         //返回指定范围的NSIndexPath实例数组
          12:- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;    // returns nil if cell is not visible or index path is out of range     //返回指定NSIndexPath实例的单元格实例
          13:- (NSArray *)visibleCells;  //返回可见的单元格的数组
          14:- (NSArray *)indexPathsForVisibleRows;  //返回可见单元格的NSIndexPath实例数组
          15:- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)sectionNS_AVAILABLE_IOS(6_0);
          16:- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)sectionNS_AVAILABLE_IOS(6_0);
          17:- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;     //滑动到指定的位置,并且可以加上动画效果
          18:- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

 

转载于:https://my.oschina.net/haoye/blog/724250

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值