標籤: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;