UITableView
UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreen_width, KScreen_height) style:UITableViewStyleGrouped];
tableView.backgroundColor = BACKGROUND_COLOR;
[self.view addSubview:tableView];
tableView.dataSource = self;
tableView.delegate = self;
self.tableView = tableView;
1.0 UITableView设置Cell的分割线
1.1 分割线样式
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 隐藏分割线
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; // 单分割线
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched; // 被侵蚀的分割线
1.2 分割线颜色
tableView.separatorColor = [UIColor redColor]
; 1.3 分割线距左右间距
// 设置端距,这里表示separator离左边和右边均15像素
tableView.separatorInset = UIEdgeInsetsMake(0,15, 0, 5);
1.4 分割线全屏显示 默认好像有分割线
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
2.0 UITableView 刷新
2.1 tableView 刷新时 会将在编辑状态的cell 键盘结束编辑,最好的办法是刷新不相关的行,避免刷新相关行
2.2 tableView 刷新或者有特定需求的时候,让tableview滚动到指定位置
2.2.1 刷新滚动到指定的 indexPath 的row 和 section
NSIndexPath *index = [NSIndexPathindexPathForRow:0inSection:0];
[self.tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];
2.2.2 刷新滚动到指定的 位置rect
[self.tableView scrollRectToVisible:CGRectMake(0, 0, KScreen_width, KScreen_height) animated:YES];