UITableView

🌰 尝试到scrollToTop = yes方法失败

 [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];

🌰 去掉系统自带的分割线

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

🌰 设置tableViewcell的分割线最左端显示

#pragma mark - 设置tableViewcell的分割线最左端显示

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{

    //  怎么去掉TableView分割线左边上的空白(必须两个同时实现)
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

       [cell setSeparatorInset:UIEdgeInsetsZero];
    }

   // Prevent the cell from inheriting the Table View's margin settings
  if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {

       [cell setPreservesSuperviewLayoutMargins:NO];
  }

  if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

       [cell setLayoutMargins:UIEdgeInsetsZero];
  }
}

🌰设置cell选中不变色

方法一:self.tableView.allowsSelection=NO;

方法二(cellforrow里面添加):cell.selectionStyle = UITableViewCellSelectionStyleNone;

🌰局部刷新

//🌰1: 局部section刷新

NSIndexSet * nd=[[NSIndexSet alloc]initWithIndex:1];//刷新第二个section

[tableview reloadSections:nd withRowAnimation:UITableViewRowAnimationAutomatic];


//🌰2: 局部cell刷新

//刷新第一个section的第二行
NSIndexPath *te=[NSIndexPath indexPathForRow:2 inSection:0];

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:te,nil] withRowAnimation:UITableViewRowAnimationMiddle];

🌰 隐藏UITableView的滚动条以及修改滚动条的颜色

  //隐藏
  self.tableView.showsVerticalScrollIndicator=NO;

   //修改颜色
  self.tableView.indicatorStyle=UIScrollViewIndicatorStyleWhite;

🌰UITabelView设置cell的线的长度

  tabelview.separatorInset = UIEdgeInsetsMake(0,18 , 0, 18);

🌰UITableViewCell上的button获取indexpath

  TableViewCell *cell = (TableViewCell *)button.superview.superview;

  NSIndexPath *indexPath = [self.tableView  indexPathForCell:cell];

🌰点击空白回收键盘

 //点击tableView回收键盘

UITapGestureRecognizer *tableViewGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(returnKeyBoard)];

tableViewGesture.numberOfTapsRequired = 1;

tableViewGesture.cancelsTouchesInView = NO;

[self.tableView addGestureRecognizer:tableViewGesture];

🌰设置headView一起滚动

#pragma mark - 设置头部一起滚动

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    CGFloat sectionHeaderHeight = 40;

    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {

    scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

  } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {

        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
  }
}

🌰 添加侧滑删除图画按钮

  - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

//设置第一个section可以删除
if ( indexPath.section == 0 ) {

    return YES;
 } else

    return NO;
}

-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

UIImage *(^imageWithView)(UIView *) = ^(UIView *view) {

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    //3. 从上下文中获取图片

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    //4. 关闭图形上下文

    UIGraphicsEndImageContext();

    return image;

};

UIColor *(^getColorWithLabelText)(NSString *, UIColor *, UIColor *) = ^(NSString *text, UIColor *textColor, UIColor *bgColor) {

    /*自定义文字

    UILabel *actionLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 78, 230)];

    actionLb.font = [UIFont boldSystemFontOfSize:14];

    actionLb.text = @"删除";

    actionLb.textColor = RedColor;

    actionLb.textAlignment = NSTextAlignmentCenter;

    actionLb.backgroundColor = bgColor;

    */

    //自定义图片
    UIView *content = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 280)];

    content.backgroundColor =BackGround_COLOR;

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 90, 40, 40)];

    view.backgroundColor =RedColor;

    view.layer.cornerRadius =20;

    view.layer.masksToBounds =YES;

    UIImageView *deleteImage = [[UIImageView alloc]initWithFrame:CGRectMake(12.5, 12.5, 15, 15)];

    deleteImage.image = [UIImage imageNamed:@"deletePic"];

    [view addSubview:deleteImage];

    [content addSubview:view];

    return[UIColor colorWithPatternImage:imageWithView(content)];

};

// 添加按钮

UITableViewRowAction *rowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"  "handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

    NSLog(@"点击了");

}];

rowAction1.backgroundColor = getColorWithLabelText(@"删除", [UIColor clearColor],BackGround_COLOR);

return@[rowAction1];

}

  //删除

  - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

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

推荐阅读更多精彩内容

  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 10,674评论 3 3
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,918评论 2 10
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,086评论 3 38
  • 更新:2018.05.24 整理了一下demo:SwiftDemo 最近比较忙,没什么时间写,断断续续写一点。 U...
    YvanLiu阅读 34,319评论 6 57
  • UITableView有两种样式: UITableView的结构:UITableView由头部,尾部,和中间一连串...
    degulade阅读 844评论 1 3