有关TableView的一些小杂碎(持续更新)

来源:互联网 发布:计算机排序算法有哪些 编辑:程序博客网 时间:2024/05/06 14:25
1.隐藏TableView的分割线

myTableView.separatorStyle = UITableViewCellSeparatorStyleNone


2.系统默认的cell点击后的颜色设置

cell.selectionStyle=UITableViewCellSelectionStyleNone;  //无色

cell.selectionStyle=UITableViewCellSelectionStyleBlue;  //蓝色

cell.selectionStyle = UITableViewCellSelectionStyleGray; //灰色


3.设置TableView分割线的颜色

[myTableView setSeparatorColor:[UIColor xxxx ]];//可以通过RGB设置


4.控制TableView分割线的长度和缩进

myTableView.separatorInset = UIEdgeInsetsMake(0, 10, 10, 10);

UIEdgeInsets UIEdgeInsetsMake 

   CGFloat top, 
   CGFloat left, 
   CGFloat bottom, 
   CGFloat right 

); 


5.在UITableViewStylePlain风格下消除TableView多余的单元格横线

[myTableView setTableFooterView:[[UIView alloc]init]];


6.消除ios7以上,TableView默认上方留有空余

self.automaticallyAdjustsScrollViewInsets =NO; 

写在- (void)viewDidLoad里面即可


7.设置TableView不能滚动

self.tableView.scrollEnabled =NO; 


8.tableview刷新某一组(带动画)  

NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    

[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];   


9.tableview刷新某一行或者某几行(带动画)

NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];    

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];


10.获取tableview的某一行cell后修改cell内容

当我们点击某个cell时,会执行下面这个方法,方法中调用另一方法执行具体操作:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        if (0 == indexPath.section) {

        [self btnActionForUserSetting:self]; 

    } 

在下面方法中怎样获取刚刚选中的那个cell,并修改它的内容呢?

- (void)btnActionForUserSetting:(id) sender {

  NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

 cell.textLabel.text= @"abc";

}

这样,被点击的cell的内容就被修改了。


11.删除TableView中某几行(带动画)
//cell = (BKCell *)button.superview;//button为cell上的button
cell = (BKCell *)button.superview.superview;
//获取位置
NSIndexPath *index = [TableView indexPathForCell:cell];  
NSArray *arr = [[NSArray alloc] initWithObjects:index, nil];
//删除掉选中的cell
[TableView deleteRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationLeft];




0 0
原创粉丝点击