【发布时间】:2018-09-10 10:58:28
【问题描述】:
请通过这些要点
- 您好,我已在代码中动态添加了一个表格视图。
- 我想在默认的 tableview 单元格中显示我自己的分隔符。
- 默认分隔符与 y 轴有一定距离。
我知道我们可以使用单元格分隔符插入属性来实现这一点的答案。 但是我遇到了奇怪的问题。
DropDownTbl=[[UITableView alloc]initWithFrame:CGRectMake(BookTypeTxt.frame.origin.x, BookTypeTxt.frame.origin.y+BookTypeTxt.frame.size.height, BookTypeTxt.frame.size.width-11, height)];
DropDownTbl.separatorStyle = UITableViewCellSeparatorStyleNone;
DropDownTbl.tag=98;
DropDownTbl.delegate=self;
DropDownTbl.dataSource=self;
[self.settingView addSubview:DropDownTbl];
[DropDownTbl reloadData];
在我的 tableview 单元格中,我添加了这种样式的分隔符,问题是这样,分隔符视图被添加两次,显示在给定图像中
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[BookTypeArray objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15.0f];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,cell.contentView.frame.size.height-1, DropDownTbl.frame.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];
cell.textLabel.font=[UIFont fontWithName:@"Arial" size:12];
return cell;
所以我决定在单元格 == nil 括号中添加 linview
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,cell.contentView.frame.size.height-1, DropDownTbl.frame.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];
}
cell.textLabel.text=[BookTypeArray objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15.0f];
cell.textLabel.font=[UIFont fontWithName:@"Arial" size:12];
return cell;
以这种方式,当重复使用单元格时,我的分隔符会消失。我只想知道为什么会这样?
【问题讨论】:
-
您是否删除了单元格的默认分隔符?
-
在添加之前删除您的特定视图单元格
标签: ios objective-c uitableview