1. UITableView
//去除tableviews的点击效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//隐藏tableView的分割线
cell.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
/*
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine,
UITableViewCellSeparatorStyleSingleLineEtched 只适用于tableView为分段的风格
*/
//根据cell的位置获得某个cell
SecondTableViewCell *cell = (SecondTableViewCell *)[self.tableViewcellForRowAtIndexPath:[NSIndexPathindexPathForRow:2inSection:0]];
//设置行高为动态
tableView.rowHeight = UITableViewAutomaticDimension;
//cell的预估行高
tableView.estimatedRowHeight = 44;
点击状态栏回到顶部
tableView.scrollsToTop = YES;
//刷新一个section
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//一个cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
实现这个新的delegate函数即可:可以设置背景色
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { view.tintColor = [UIColor clearColor]; }改变文字的颜色
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view; [footer.textLabel setTextColor:[UIColor whiteColor]]; }cell的4种格式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell; switch (indexPath.row) { case 0: { cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL1]; cell.backgroundColor = [UIColor yellowColor]; cell.selectionStyle = UITableViewCellSelectionStyleDefault; } break; case 1: { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CELL2]; cell.backgroundColor = [UIColor redColor]; cell.selectionStyle = UITableViewCellSelectionStyleGray; } break; case 2: { cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CELL2]; cell.backgroundColor = [UIColor blueColor]; cell.selectionStyle = UITableViewCellSelectionStyleBlue; } break; case 3: { cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CELL4]; cell.backgroundColor = [UIColor purpleColor]; cell.selectionStyle = UITableViewCellSelectionStyleDefault; } break; } cell.imageView.image = [UIImage imageNamed:@"warning_btn"]; cell.detailTextLabel.text = @"detailTextLabel"; cell.textLabel.text = @"textLabel"; return cell;}