【发布时间】:2012-04-28 06:53:51
【问题描述】:
有没有办法将类别添加到您无法访问其头文件的类?
出于测试目的,我想向UITableViewCellDeleteConfirmationControl 添加一个类别,但该类(据我所知)是私有框架的一部分。
我该怎么做?
详细说明(根据 mihirios 的要求):
我正在尝试扩展 Frank 测试框架,以模拟点击当您尝试删除 UITableViewCell 时出现的确认按钮(大红色“删除”按钮)。 Frank 将tap 方法添加到UIControl。出于某种原因,Frank 通常的点击控件方式不适用于UITableViewCellDeleteConfirmationControl 类(它是UIControl 的子类)。
我已经创建了一个解决方法。我给UITableViewCell添加了一个分类,方法如下。
- (BOOL)confirmDeletion {
if (![self showingDeleteConfirmation]) {
return NO;
}
UITableView *tableView = (UITableView *)[self superview];
id <UITableViewDataSource> dataSource = [tableView dataSource];
NSIndexPath *indexPath = [tableView indexPathForCell:self];
[dataSource tableView:tableView
commitEditingStyle:UITableViewCellEditingStyleDelete
forRowAtIndexPath:indexPath];
return YES;
}
这会找到表的数据源并调用其tableView:commitEditingStyle:forRowAtIndexPath: 方法,该方法(根据UITableView 的文档)是用户点击确认按钮时系统所做的。
这可行,但我更愿意通过向其添加tap 方法来使UITableViewCellDeleteConfirmationControl 看起来是一个可点击的按钮,覆盖Frank 的默认方法。 tap 方法会找到包含确认按钮的单元格,然后调用 [cell confirmDeletion]。
当我尝试为 UITableViewCellDeleteConfirmationControl 声明一个类别时,编译器抱怨它“无法解析接口 'UITableViewCellDeleteConfirmationControl'。”
当我尝试使用某人使用类转储生成的头文件时,链接器抱怨它找不到符号 _OBJC_CLASS_$_UITableViewCellDeleteConfirmationControl。
【问题讨论】:
-
能否详细说明您的问题?
标签: objective-c ios objective-c-category