Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bringing a subview in a UITableViewCell to front

Tags:

uitableview

I added a bunch of UILabel views to a UITableViewCell's contentView, some of which may overlap. On tapping any of the labels, I want to trigger some actions. Also, I want to bring up the tapped label to the top.

Using a UITapGestureRecognizer on the labels, I can figure out which one is tapped and perform the actions. But bringing the tapped and overlapped label to the front does not work. This is what I am trying:

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...");
    }
}

I do get the NSLog output above, so I know that the bringSubviewToFront is being called on the appropriate cell's contentView. But no change in the subview layout order.

Ideas?

like image 322
raheel Avatar asked Jul 21 '11 19:07

raheel


2 Answers

One thing to explore is zposition on the uitablviewcell's layer.

This successfully put on tableviewcell in front of another for me:

    cell1.layer.zPosition=3 ;//above

    cell2.layer.zPosition=2 ;//below 
like image 163
yeahdixon Avatar answered Oct 13 '22 04:10

yeahdixon


bringSubviewToFront: didn't work for me either

Try insertSubview:belowSubview: where the latter subview is a super view such as tab bar, nav bar, table view.

like image 32
defvol Avatar answered Oct 13 '22 04:10

defvol