我正在尝试使我的子视图变得前卫,因为删除按钮不断消失。无法将删除子视图带到前面
@implementation MyCell : UITableViewCell
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *subview in self.subviews) {
for (UIView *subview2 in subview.subviews) {
NSLog(@"HERE!");
if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
NSLog(@"got inside the if!");
[subview2 sendSubviewToBack:subview];
[subview bringSubviewToFront:subview2];
[self.superview bringSubviewToFront:subview2];
}
}
}
}
@end
我分类了UITableViewCell。两个NSLogs都在打印,所以我知道它已经进入,但我已经尝试了所有这些方法中的三种将视图放在前面。任何想法,为什么这不会工作?
您需要将所有自定义单元格的自定义视图放在单元格的“self.contentView”中,而不是直接放在“self”中。 – rmaddy
像这样'[self.contentview sendSubviewToBack:subview];' '[self.contentview bringSubviewToFront:subview2];' '[self.contentview bringSubviewToFront:subview2];'而不是? – Inbl
不。当你添加子视图时,将它们添加到'contentView'。那么这些代码都不需要。 – rmaddy