UITableViewCell和消失的分隔符

Jak*_*kub 3 objective-c uitableview ios

我尝试在我的UITableView中实现我自己的简单样式的单元格,我有分隔符的问题.在正常视图下工作得很好,但是当我选择一个单元格时,它会消失.我尝试添加到我的customSelect视图分隔符,但后来我无法在任何地方看到分隔符.如何在选定的单元格中添加分隔符?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyCellIdentifier = @"MyCellIdentifier";

    UITableViewCell *cell = [wallMenuTableView dequeueReusableCellWithIdentifier:MyCellIdentifier];

    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];

        MenuItemModel *mItem = [menu.menuPositions objectAtIndex:indexPath.row];
        cell.textLabel.text = mItem.displayName;
        cell.textLabel.textColor = [UIColor colorWithRed:0.70 green:0.70 blue:0.70 alpha:1.0];
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:16];
        cell.textLabel.shadowColor = [UIColor blackColor];
        cell.textLabel.shadowOffset = CGSizeMake(0.0, 1.0);

        customSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, (cell.frame.origin.y), 320, 2)];
        customSeparator.backgroundColor=[UIColor blackColor];
        [customSeparator.layer setShadowOffset:CGSizeMake(0.0, 0.8)];
        [customSeparator.layer setShadowOpacity:0.8];
        [customSeparator.layer setShadowRadius:0.8];
        [customSeparator.layer setShadowColor:[UIColor grayColor].CGColor];
        [cell.contentView addSubview:customSeparator];

        customSelect = [[UIView alloc] initWithFrame:CGRectMake(0, (cell.frame.origin.y+2), cell.frame.size.width, cell.frame.size.height)];
        //[customSelect addSubview:customSeparator];
        customSelect.backgroundColor = [UIColor clearColor];
        [cell setSelectedBackgroundView:customSelect];

    }

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

目前的结果:

在此输入图像描述

wil*_*key 7

对于分隔符,请使用UIImageView而不是简单的UIView.设置图像值(这很重要!)而不是backgroundColor值,并使用缩放来拉伸图像以进行填充.