我有一个自定义的TableViewCell。在这个cell中,我在两侧添加了两个交叉图标(使用Unicode)。当用户滑动单元格时,它将在侧面显示交叉图标。
我使用了上面的代码来实现这个功能。_crossLabel确实被添加到了自定义的TableView单元格中。
我使用Reveal App检查我的iOS应用程序的布局
。我可以看到_crossLabel已经添加到我的单元格中。但是在我的iOS 7模拟器中看不到交叉图标。我尝试了不同的方法来添加子视图,但是没有一个方法起作用。
- (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;
}
我使用了上面的代码来实现这个功能。_crossLabel确实被添加到了自定义的TableView单元格中。
我使用Reveal App检查我的iOS应用程序的布局
![enter image description here](https://istack.dev59.com/kipBz.webp)