第一種方法
1、加方法 -(void)setExtraCellLineHidden: (UITableView *)tableView
{
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[tableView setTableFooterView:view];
[view release];
} 2、在
- (void)viewDidLoad
{
[super viewDidLoad];
//設定tableView不能滾動
[self.tableView setScrollEnabled:NO];
//在此處調用一下就可以啦 :此處假設tableView的name叫:tableView
[self setExtraCellLineHidden:self.tableView];
}
當tableview的dataSource為空時,也就是沒有資料可顯示時,該方法無效,隻能在numberOfRowsInsection函數,通過判斷dataSouce的資料個數,如果為零可以将tableview的separatorStyle設定為UITableViewCellSeparatorStyleNone去掉分割線,然後在大于零時将其設定為
UITableViewCellSeparatorStyleSingleLine
第二種方法
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
separatorLine.tag = 4;
[cell.contentView addSubview:separatorLine];
[separatorLine release];
}
// Setup default cell setttings.
...
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
...
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
...
In viewDidLoad:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
原文位址:
http://blog.csdn.net/l_ch_g/article/details/9290727
其部落格位址:
http://blog.csdn.net/l_ch_g?viewmode=contents