从 TTTableLinkedItemCell 访问自定义单元格中的属性
我在实现自定义单元时遇到一个小问题。基本上在我的自定义单元子类中(TTTableLinkedItemCell 的子类) 我有一个称为选项的 BOOL。我希望能够在我的内部使用这个 BOOL
+ (CGFloat)tableView:(UITableView *)tableView rowHeightForObject:(id)item {
,但是,似乎这是不可能的。有解决办法吗?
这些选项用于动态调整单元格的高度,无论是否设置都
定义了单元格的高度。
更新:
我在被调用的函数中尝试了以下操作:
CustomCell* cell = (CustomCell *) [self.tableView cellForRowAtIndexPath:indexPath];
((RKMappableObjectTableItem *)[cell object]).options = YES;
在我的 rowHeightForObject 中我有:
+ (CGFloat)tableView:(UITableView *)tableView rowHeightForObject:(id)item {
float optionsHeight = 0.0;
if (((RKMappableObjectTableItem *) item).options)
optionsHeight = 25.0;
}
这是我如何设置它的:
@interface RKMappableObjectTableItem : TTTableLinkedItem {
NSObject* _object;
BOOL _options;
}
@property (nonatomic, retain) NSObject* object;
@property (nonatomic, assign) BOOL options;
+ (id)itemWithObject:(NSObject*)object;
@end
但是 BOOL 始终为 NO,就好像它从未设置过一样。这是为什么呢? 我做错了什么?
I am having a small issue in my implementation of my custom cell. Basically in my custom cell subclass (subclass of TTTableLinkedItemCell)
I have a BOOL called options. I want to be able to use this BOOL inside my
+ (CGFloat)tableView:(UITableView *)tableView rowHeightForObject:(id)item {
but, it seems that it is not possible. Is there any work around for this?
The options is used to adjust the height of the cell dynamically, whether it's set or not
defines the height of the cell.
UPDATE:
I have tried the following in my function that is called:
CustomCell* cell = (CustomCell *) [self.tableView cellForRowAtIndexPath:indexPath];
((RKMappableObjectTableItem *)[cell object]).options = YES;
and in my rowHeightForObject I have:
+ (CGFloat)tableView:(UITableView *)tableView rowHeightForObject:(id)item {
float optionsHeight = 0.0;
if (((RKMappableObjectTableItem *) item).options)
optionsHeight = 25.0;
}
Here's how I set it up:
@interface RKMappableObjectTableItem : TTTableLinkedItem {
NSObject* _object;
BOOL _options;
}
@property (nonatomic, retain) NSObject* object;
@property (nonatomic, assign) BOOL options;
+ (id)itemWithObject:(NSObject*)object;
@end
However the BOOL is always NO, it's as if it's never set.. Why is this?
What did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行此操作的方法是为您的
TTTableViewItem
创建一个自定义类。该单元格实际上应该是“哑的”,并且仅显示自定义项目中包含的信息。因此,我会将您的options
bool 并将其存储在自定义项目子类中,而不是自定义单元格中。这就是为什么该方法作为类方法存在并且您传入该项目,而不是实例方法。The way to do this is to make a custom class for your
TTTableViewItem
. The cell should really be "dumb" and only display the information contained in the custom item. So I would take youroptions
bool and store it in the custom item subclass, not the custom cell. This is why the method exists as a class method and you are passed in the item, rather than an instance method.尝试这样的事情:
Try something like this: