【发布时间】:2011-12-15 01:00:34
【问题描述】:
所以我不确定这个 dequeueReusableCellWithIdentifier 是如何工作的,以及我正在寻找的是否可能。我有一个带有 BOOL showIcon 的自定义 UITableViewCell。在 TableViewCell 中,如果它是真的,我会显示它,否则,我不会在我的单元格上显示这个图标。在我的 cellForRowAtIndexPath 中,我从模型中获取数组中的对象,并将其设置为 UITableViewCell 属性。
这首先适用于我屏幕上可见的内容。然后当我在桌子上向下滚动时,它不起作用,我应该为 showIcon 看到的值只是不显示。然后当我滚动回顶部时,原来的图标不在那里了。在这种情况下,dequeueReusableCellWithIdentifier 仍然是我想要使用的吗?还是我在其中设置和显示数据时做错了什么?谢谢一堆。
代码:
在我的自定义 UITableViewCell 上,我有一个
BOOL showIcon;
在我的 cellForRowAtIndexPath 方法中,我使用 UINib 方法来获取我的自定义 UITableViewCell,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
static NSString *OrderTableViewCellIdentifier = @"OrderTableViewCellIdentifier";
OrderTableViewCell *cell = (OrderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:OrderTableViewCellIdentifier];
if (cell == nil) {
UINib *cellNib = [UINib nibWithNibName:@"OrderTableViewCell" bundle:nil];
[cellNib instantiateWithOwner:self options:nil];
cell = self.TbvCell;
[cell.CheckmarkButton addTarget:self action:@selector(CheckmarkButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.TbvCell = nil;
}
Order *order = [orderArray objectAtIndexPath:row];
cell.order = order;
}
然后在我的 TableViewCell 中,是这样的:
@property (nonatomic, retain) Order *order;
@property (nonatomic, retain) UIImageView *icon;
重写的设置器:
- (void)setOrder:(Order *)newOrder {
if (!order.showIcon) {
icon.hidden = YES;
}
}
【问题讨论】:
标签: iphone uitableview