ios - 无法将删除 subview 置于前面

标签 ios objective-c uitableview

我正在尝试将我的 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 放在前面。任何想法为什么这不起作用?

最佳答案

subview2subview 的 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/

相关文章:

ios - 声明 UInt 类型的 var 时出错

带有 2 个输入字段的 iOS 搜索栏(例如要搜索的名称和要搜索的位置的第二行)

ios - 此 Objective-C 代码不会更改标签文本的颜色

ios - 自定义 UITableViewCell 不显示标签

ios - UITableViewCell 部分重复

由 xib (nib) 文件初始化的 iOS Swift 子类化 ViewController

objective-c - 使用 KeychainItemWrapper 保存到 iOS 钥匙串(keychain)时出错

ios - 带有 UIImageView 的自定义 UITableViewCell 不加载某些单元格的图像

ios - tableView heightForRowAtIndexPath 不工作

javascript - 钛的Paypal集成问题