UITableview

cell常用属性:
imageview
textLabel
detailTextLabel
accessoryType
accessoryView

cell背景颜色属性:
backgroundcolour
backgroundView
selectedbackgroundView
点击颜色不同,可以设置backgroundView 为一个新的UIView,然后设置selectbackgroundVeiw 为新View即可;
rowHeight 统一的行高
separatorColour 分隔线颜色
separatorStyle 分隔线样式
tableHeaderView 一般放广告
tableFooterView 一般可以放加载更多
cell类型:

//这句话不显示多余的单元格 self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //右边字幕筛选
sectionIndexTitlesfortableview方法 // 这句话不显示单元格之间的分割线 _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 这句话在单元格的最后显示一个箭头 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 可以在后面箭头的地方设置各种View,比如开关switch
cell.accessotyView = [UISwitch alloc]init]; //--- 点击cell的时候 cell不会产生高亮状态 --- cell.selectionStyle = UITableViewCellSelectionStyleNone; // --- 写在viewdidload里面cell自适应高度 ---- tableView.rowHeight = UITableViewAutomaticDimension; // 自适应单元格高度 tableView.estimatedRowHeight = 50; //先估计一个高度 // 去掉UItableview headerview黏性(sticky) - (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); } } // 获取手势点击的是哪一个cell的坐标 NSIndexPath *indexPath = [self.tableView indexPathForCell:((UITableViewCell *)longPress.view)]; // 局部刷新 //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; //一个cell刷新 NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0]; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; // 关于UITableView如何跳转到最后一行或者任意指定行。 其实现如下: [self.chatTableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow:[self.chatArray count]-1 inSection:0] atScrollPosition: UITableViewScrollPositionBottom animated:NO]; // 点击button时获取button所在的cell的indexpath UIButton *button = sender; HeroDermaTableViewCell *cell = (HeroDermaTableViewCell *)[[button superview] superview]; NSIndexPath *indexPath = [_tableView indexPathForCell:cell];

tableview 最后一行显示不全,可以设置contentInset 设置偏移值.大多数因为tableview的高度不够造成的.
分组与不分组的区别:
plain:向下拖动的时候,header和footer不随着拖动.

Group:一起拖动

 tableView 只刷新一行的方法:

NSIndexPath *index = [NSIndexPath indexPathForRow:alertView.tag inSection:0];

[self.tableView reloadRowsAtIndexPaths;@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];


 

原文地址:https://www.cnblogs.com/yangqinglong/p/5502227.html