Пожалуйста, пройдите эти пункты
- Привет! Я динамически добавил табличное представление в свой код.
- Я хочу показать свой собственный разделитель в ячейке таблицы по умолчанию.
- По умолчанию разделитель расположен на некотором расстоянии от оси Y.
Мне известен ответ, что мы можем использовать свойство inset для разделения ячеек для достижения этой цели.
Но с проблемой я столкнулся с чем-то странным.
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];
И в моей ячейке табличного представления я добавил разделитель в этом стиле, проблема в том, что представление разделителя добавляется дважды, как показано на данном изображении
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;
Поэтому я решил добавить linview в ячейку == nil круглых скобок
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;
Таким образом, мой сепаратор исчезает при повторном использовании клетки. Я просто хочу знать, почему это происходит?