表视图有时为了美观,有的一行可能不需要显示分割线,比如下图
要实现以上的效果,即不显示最后一行的分割线,可以在表视图下面的代理方法中实现
<span style="font-size:18px;">- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == _dataArr.count - 1) {
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}else{
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
}</span>
该方法是在显示每一个cell时调用,有多少个cell,就会走多少次。