2011-07-21 24 views
4

我向UITableViewCellcontentView添加了一堆UILabel视图,其中一些可能重叠。在点击任何标签时,我想触发一些操作。另外,我想把敲击标签放在最上面。将UITableViewCell中的子视图带到前面

在标签上使用UITapGestureRecognizer,我可以找出哪一个被点击并执行操作。但将轻拍和重叠标签带到前面不起作用。这就是我想:

UILabel *foundLabel = ....; // find the label 
for (UITableViewCell *acell in theTable.visibleCells) { 
    UIView *cellContentView = acell.contentView; 
    if ([cellContentView.subviews containsObject:foundLabel]) { 
     [cellContentView bringSubviewToFront:foundLabel]; 
     NSLog(@"should bring to front..."); 
    } 
} 

我得到上面的NSLog输出,所以我知道bringSubviewToFront被称为在相应的单元格的contentView。但是在子视图布局顺序中没有改变。

想法?

+0

你找到了一个解决方案?有兴趣知道我有类似的问题。 –

回答

3

bringSubviewToFront:并没有为我工作,要么

尝试insertSubview:belowSubview:其中,后者是子视图超视如标签栏,导航栏,表视图。

+0

注意:insertSubview不会在后续调用中创建额外的UIView副本。 – rodowi

12

有一点需要研究的是uitablviewcell层上的zposition。

这成功地穿上tableviewcell在另一条战线对我来说:

cell1.layer.zPosition=3 ;//above 

    cell2.layer.zPosition=2 ;//below