【问题标题】:Use UITableViewCellDeleteConfirmationControl to know what is the current cell's subview使用 UITableViewCellDeleteConfirmationControl 知道当前单元格的子视图是什么
【发布时间】:2013-03-06 15:23:18
【问题描述】:

这样使用 UITableViewCellDeleteConfirmationControl 可以吗:

- (void)layoutSubviews {
    [super layoutSubviews];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.0f];

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) { 
        CGRect newFrame = subview.frame;
        newFrame.origin.x = 200;
        subview.frame = newFrame;
        }
        else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {             
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 100;
            subview.frame = newFrame;
        }
        else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellReorderControl"]) {             
        CGRect newFrame = subview.frame;
        newFrame.origin.x = 200;
        subview.frame = newFrame;
       }
   }
   [UIView commitAnimations];
}

即使 UITableViewCellDeleteConfirmationControl 不是公共类?

【问题讨论】:

    标签: ios objective-c cocoa-touch uitableview delete-row


    【解决方案1】:

    由于您正在比较字符串相等性,因此您没有公开任何私有 API,因此应该有资格提交 AppStore。

    我已经成功地在我自己的应用程序中使用了这种相等检查,该应用程序已进入 AppStore。

    【讨论】:

      【解决方案2】:

      首先,类不是字符串。您应该使用NSStringFromClass([subview class]) 来获取类名的字符串表示形式。

      其次,将整个类名作为字符串文字是一个很大的风险,你不应该把它这么明显。例如,您可以测试名称是否包含您要查找的名称的一部分:[className rangeOfSubstring:@"DeleteConfirmation"].location != NSNotFound

      第三,不公开的原因是因为它是 tableview 单元格的私有实现。一个很好的例子,为什么你不应该在 iOS7 上,cell 的整个实现已经完全改变了。您在示例中提到的类不再使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-10
        • 2023-03-28
        • 1970-01-01
        • 1970-01-01
        • 2020-12-23
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多