tableview分割线顶头显示以及删除多余的行

iOS:UITableView-删除多余的行,以及cell系统分割线顶头


1.在屏幕上显示特定的行数,但是由于屏幕大小和UITableView的高度会显示多余的行,这里需要对其进行删除

[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

2.UITableView默认的cell分割线前端距离屏幕会有一段空隙,有时我们实现时不需要间隔(例如,qq消息列表的最后一个消息行,它就是顶头显示的)

//首先写一个函数

-(void)setLastCellSeperatorToLeft:(UITableViewCell *)cell{

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

[cell setSeparatorInset:UIEdgeInsetsZero];

}

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

[cell setLayoutMargins:UIEdgeInsetsZero];

}

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

[cell setPreservesSuperviewLayoutMargins:NO];

}

}

//其次在-(UITableViewCell *)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath中进行调用

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

static NSString *strID =@"cellID";

UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:strID];

if(!cell) {

cell =[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:strID];

}

//最后一行分割线顶头显示

if(indexPath.row== _dataSource.count-1){

[selfsetLastCellSeperatorToLeft:cell];

}

returncell ;

}

你可能感兴趣的:(tableview分割线顶头显示以及删除多余的行)