无法在iOS7上看到动态子视图(在iOS6上工作)

Jak*_*Lin 4 objective-c uitableview addsubview ios ios7

我有一个自定义的TableViewCell.在单元格中,我将两个交叉图标(使用unicode)添加到单元格的两侧.当用户平移单元格时,它将在侧面显示十字图标.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // add a cross
        _crossLabel = [self createCueLabel];
        _crossLabel.text = @"\u274C";
        _crossLabel.textAlignment = NSTextAlignmentLeft;
        // none of the following code works
        [self insertSubview:_crossLabel aboveSubview:self];
        [self insertSubview:_crossLabel belowSubview:self];
        [self addSubview:_crossLabel];

        _crossLabel2 = [self createCueLabel];
        _crossLabel2.text = @"\u274C";
        _crossLabel2.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_crossLabel2];

        // add a pan recognizer
        UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

我使用上面的代码来实现这一点.并且_crossLabel确实添加了Custom TableView Cell.

我使用Reveal App来检查我的iOS应用程序的布局 在此输入图像描述 我可以看到_crossLabel已添加到我的Cell中.但我在iOS 7模拟器中看不到十字图标.我尝试了不同的方法来添加subView,但它们都不起作用.

在此输入图像描述

但它在iOS6上完美运行,当我在Reveal App中检查时,布局与iOS 7完全相同.

谢谢你的帮助.

the*_*ven 11

确保添加到单元格的contentView,[self.contentView addSubView:_crossLabel2];而不是单元格本身.您将看到使用Reveal并检查iOS7时,在UITableViewCell UIKit中添加/滑入了单元格视图上方的UITableViewCellSCrollView,因此请小心insertSubview:belowSubview调用.同样,从显示的OutlineView的屏幕截图中,"LocationCell"视图显示为灰色,这意味着它是隐藏的.

编辑以供将来参考:
在iOS 7中,新的UITableViewCellScrollView具有它的'clipToBounds'属性集.这是一个黑客,但如果你[self.contentView.superview setClipsToBounds:NO].superview是iOS7上的UITableViewCellScrollView和iOS6上的单元本身

  • 好吧,在iOS 7中,新的UITableViewCellScrollView具有'clipToBounds'属性集.使用"显示"选择单元格滚动视图,并在检查器中取消选中clipsToBounds.这是一个黑客,但如果你`[self.contentView.superview setClipsToBounds:NO]`,应该工作.iOS 6中的contentview的superview是单元本身,而在iOS 7中它是单元scrollView (4认同)