在编辑模式下更改 UITableViewCell 中红色减号按钮的位置



这段代码在iOS 5和6上的UITableViewCell子类中效果很好:

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
        CGRect newFrame = subview.frame;
        //Use your desired x value
        newFrame.origin.x = 280;
        subview.frame = newFrame;    
}

在iOS 7上调试我的应用程序时,我发现上面的所有子视图都称为UITableViewCellContentView,并且无法知道UITableViewCellEditControl子视图的位置。

有没有更好的解决方案来做上述事情?

在调试时,我发现iOS 7中的所有子视图现在都称为"UITableViewCellEditControl"。我尝试记录所有子视图子视图,发现UITableViewCellEditControl现在是子视图的子视图。这是一个丑陋的临时解决方案:

for (UIView *subview in self.subviews)
    {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 280;
            subview.frame = newFrame;
        }
        else
        {
            if(IS_OS_7_OR_LATER)
            {
                for(UIView *subsubview in subview.subviews)
                {
                    if ([NSStringFromClass([subsubview class]) isEqualToString:@"UITableViewCellEditControl"]) {
                        CGRect newFrame = subsubview.frame;
                        newFrame.origin.x = 280;
                        subsubview.frame = newFrame;
                    }
                }
            }
        }

相关内容

最新更新