我正在尝试将我的 subview 放在前面,因为删除按钮不断消失。
@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。两个 NSLog 都在打印,所以我知道它已经进入了那里,但是我已经尝试了所有 3 种方法来将 View 放在前面。任何想法为什么这不起作用?
最佳答案
subview2
是 subview
的 subview ,它是 self
的 subview . sendSubviewToBack:
的接收者或 bringSubviewToFront:
message 必须是作为参数给出的 View 的 super View 。因此,只有您调用的第二个电话是有效的。正确的电话是
[self.superview bringSubviewToFront:self];
[self bringSubviewToFront:subview];
[subview bringSubviewToFront:subview2];
(对于
sendSubviewToBack:
也是如此。)至于您的实际问题,我无法从发布的代码中找出您正在使用的 View 层次结构,但它似乎不正确。您可能不应该将自定义 View 作为
self
的直接 subview 。 , 而是作为 self.contentView
的 subview (根据 Apple's documentation )。
关于ios - 无法将删除 subview 置于前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22135945/