tableview

//---------------------单元格地分割线---------------------------------

    _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];

    

    

    

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值