//---------------------单元格地分割线---------------------------------
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//---------------------单元格地分割线颜色---------------------------------
_tableView.separatorColor = [UIColor redColor];
//---------------------单元格地头视图---------------------------------
UIView *tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 150)];
tableHeaderView.backgroundColor = [UIColor purpleColor];
_tableView.tableHeaderView = tableHeaderView;
//---------------------单元格尾部视图---------------------------------
UIView *tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 150)];
tableFooterView.backgroundColor = [UIColor purpleColor];
_tableView.tableFooterView = tableFooterView;
// tableView.rowHeight = 44;
//---------------------在头视图上添加一个按钮--------------------------------
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.backgroundColor = [UIColor whiteColor];
btn.frame = CGRectMake(50, 50, 60, 40);
[btn setTitle:@"点我" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[_tableView.tableHeaderView addSubview:btn];
}
#pragma mark - tableViewdelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify = @"cell";
UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:identify];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
cell.textLabel.text = [_array objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - UItableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 100;
}else if (indexPath.row == 4)
{
return 150;
}
return 44;
}
-(void)btnAction
{
// NSIndexPath *indexPath = [NSIndexPath indexPathForItem:2 inSection:0];
//----------------------------滚动到指定位置-------------------------------------
// [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
//----------------------------删除单元格-------------------------------------
/*
reloadDate 只适合删除数据地单元格一处
*/
// [_array removeObjectAtIndex:0];
//
// [_tableView reloadData];
//----------------刷新单元格 ----------------------
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
NSIndexPath *indexPath1 = [NSIndexPath indexPathForItem:1 inSection:0];
NSArray *indexPaths =@[indexPath,indexPath1];
[_array exchangeObjectAtIndex:0 withObjectAtIndex:1];
//---------------- 取到单元格 ----------------------
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
NSArray *cells = [_tableView visibleCells];
[_tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft];
}