【UIKit】UITableView.08 常用屬性

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   io   資料   

UITableView.08 常用屬性:

 

   以片轉自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;
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.