1

除了我最近问的这个问题,我能够成功地让解释视图出现在表格视图的前面,但是我现在遇到了一个问题,当表格视图首次加载时,表格视图的分隔线在我的解释视图下方短暂可见。尽管设置了解释视图的背景颜色,将其设置为不透明并将其置于前面。这只是一个短暂的闪光,但它很明显且分散注意力。

这是我的代码(_explanationView是我在视图控制器的方法中UIView设置的实例变量):nildealloc

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.separatorColor = [UIColor darkGrayColor];

    CGRect frame = CGRectMake(50.0f, 120.0f, 220.0f, 155.0f);
    _explanationView = [[UIView alloc] initWithFrame:frame];
    _explanationView.userInteractionEnabled = NO;
    _explanationView.backgroundColor = [UIColor whiteColor];
    _explanationView.opaque = YES;
    _explanationView.layer.borderColor = [UIColor darkGrayColor].CGColor;
    _explanationView.layer.borderWidth = 1.0f;
    _explanationView.layer.cornerRadius = 10.0f;
    _explanationView.layer.masksToBounds = YES;

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 0.0f, 180.0f, 145.0f)];
    label.backgroundColor = [UIColor whiteColor];
    label.textColor = [UIColor darkGrayColor];
    label.numberOfLines = 0;
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.font = [UIFont systemFontOfSize:14.0f];
    label.text = @"Explanation of this screen...";

    [_explanationView addSubview:label];
    [self.tableView addSubview:_explanationView];
}

我发现我必须在viewDidAppear:方法中将解释视图放在前面,否则 tableview 的分隔线在下面永久可见。

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.tableView bringSubviewToFront:_explanationView];
}

我可以做些什么来阻止表格视图的分隔线在我的自定义视图下短暂可见?

4

1 回答 1

1

我发现这个答案表明可以在该layoutSubviews方法中处理 tableView 中自定义子视图的顺序。

于 2013-05-06T20:02:42.740 回答