TableView
屬性
// 設置每一行cell的高度 @PRoperty (nonatomic)CGFloat rowHeight; // 設置每一組頭部的高度 @property (nonatomic)CGFloat sectionHeaderHeight; // 設置分割線顏色 @property (nonatomic, retain) UIColor *separatorColor // 設置表頭控件 @property (nonatomic, retain) UIView *tableHeaderView; // 設置表尾控件 @property (nonatomic, retain) UIView *tableFooterView; // 2.組頭組尾的高 self.tableView.sectionHeaderHeight = 55; self.tableView.sectionFooterHeight = 22; // 3.設置整個tablView的頭部/尾部視圖 self.tableView.tableHeaderView = [[UISwitch alloc] init]; self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeInfoDark]; // 4.設置我們分割線顏色(clearColor相當于取消系統分割線) //self.tableView.separatorColor = [UIColor clearColor]; // 5.設置分割線樣式 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//cell有多少組-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //告訴tableView第section組有多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//告訴tableView每一行顯示什么內容(tableView的每一行都是UITableViewCell)-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //告訴tableView第section組的頭部標題文字-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section // 告訴tableView第section組的尾部標題文字-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section//返回每一組的索引標題- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView // 返回每個cell的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//刪除數據- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;//
// 只要實現了這個方法,左滑出現按鈕的功能就有了(一旦左滑出現了N個按鈕,tableView就進入了編輯模式, tableView.editing = YES) -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath //左滑cell時出現什么按鈕 -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"關注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了關注"); // 收回左滑出現的按鈕(退出編輯模式) tableView.editing = NO; }]; UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { [self.wineArray removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]; return @[action1, action0];} //代理方法獲取點滴選中行,行號 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; //允許編輯選中行 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
UITableViewCell
//設置cell右邊的指示樣式//accessoryView的優先級 > accessoryType//cell.accessoryView = [[UISwitch alloc] init];@property (nonatomic) UITableViewCellAccessoryType accessoryType;// default is UITableViewCellAccessoryNone. use to set standard type
Cell 創建
注冊創建
[self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];//注冊后可以直接從緩存中找創建好的UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
非注冊創建
先從緩存持中查找
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
查不到在創建
if (nil==cell) {cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; }
新聞熱點
疑難解答