iOS 开发之UITableView的相关设置汇总

UITableView是我们开发中最常用的一个控件,几乎每一个app的开发中都会用上。今天这篇文章主要是将之前开发中常用的UITableView和UITableViewCell的一些相关设置做了一个总结。第一次写,值得纪念!

设置没有选中状态

cell.selectionStyle = UITableViewCellSelectionStyleNone;

取消tableView的右侧滚动条(垂直)、水平

_tableview.showsVerticalScrollIndicator = NO;
_tableView.showsHorizontalScrollIndicator = NO;

设置cell的右侧附件类型(勾、详情、详情加右箭头>)

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

去掉tableViewCell的行分割线

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

设置分割线的位置 上左下右

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {                 [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 45, 0, 0)];             }

设置cell分割线的颜色

[self.tableView setSeparatorColor:[UIColor clearColor]];

自定义cell分割线

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
 
   UITableViewCell *cell = nil;  
   cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    if (cell == nil) {     

       cell = [[UITableViewCell   alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];       

       cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"huicellacce"]]; 

       cell.backgroundColor = [UIColor clearColor]; //        cell.selected = YES;        

       UIImageView *imageViewSepE = [[UIImageView alloc]initWithFrame:CGRectMake(47, 49, 200, 1)];  

       imageViewSepE.image = [UIImage imageNamed:@"godline"];         [cell.contentView addSubview:imageViewSepE];

        }
}

刷新tableView的某个section

[_tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];

刷新tableView的某行或几行

NSIndexPath *indexPath1=[NSIndexPath indexPathForRow:1 inSection:1];  NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:1];    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,indexPath1, nil] withRowAnimation:UITableViewRowAnimationNone];

哈哈!第一次写,这是本人自己做的一点总结,如果还有需要补充的可以评论或者私信我!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,958评论 3 38
  • 一、初始化方法 1:TableView风格设置。 - (instancetype)initWithFrame:(C...
    iOS_SXH阅读 5,885评论 1 10
  • 本篇通过实现一个自定义的栈,来学习Go语言的自定义类型及其方法首先栈的概念不用多说,它是一种支持从顶端插入或删除的...
    码码码码阅读 5,390评论 2 5
  • 文/梓星 我听见远处 孩子们兴奋的呼喊声 年少的心 总是那般无所畏惧 似乎雨季 也能嗅到阳光的味道 可是风儿不知怎...
    梓莘阅读 1,729评论 4 4
  • 罗帐高,罗帐高, 少年买醉逞逍遥。 欢纵忘思归蜀事, 凉生难过奈何桥。
    临风诵书阅读 1,677评论 0 2