我正在处理UITableView谁显示每个价格范围值条目。 我使用循环来显示价格范围。我在哪里寻找我的灵魂,因为当我上下滚动时,每个已经显示,隐藏并重新显示的细胞都叠加了“美元”的图像,而且它很丑,看到图片。Objective-c UITableView单元格图像叠加
我如何设置初始化我的手机:
PoiAllTableCell *cell = (PoiAllTableCell *)[tableView dequeueReusableCellWithIdentifier:@"PoiAllCell" forIndexPath:indexPath];
我使用此代码显示美元的ImageView:
for (int i =0; i < 4;) {
PriceRangeImageView *img = [PriceRangeImageView new];
if (i < _currentPoi.priceRange) {
[img initWithXMultiple:i withColor:_appDelegate.mainColor];
}
else{
[img initWithXMultiple:i withColor:_appDelegate.blackColor];
}
[cell.priceRangeView addSubview:img];
i++;
}
我如何显示图像:
#import "PriceRangeImageView.h"
@implementation PriceRangeImageView
- (void)initWithXMultiple:(int)xMultiple withColor:(UIColor *)color{
if (self.image == nil) {
self.frame = CGRectMake(xMultiple*16,0,16,16);
self.image = [UIImage imageNamed:@"dollar_icon"];
self.image = [self.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.tintColor = color;
}
}
@end
这里是我的手机:
#import <UIKit/UIKit.h>
#import "PriceRangeView.h"
@interface PoiAllTableCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *poiTitleLabel;
@property (weak,nonatomic) IBOutlet UIImageView *poiImageView;
@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;
@property (weak, nonatomic) IBOutlet UILabel *kmStaticLabel;
@property (weak, nonatomic) IBOutlet UILabel *separatorLabel;
@property (weak, nonatomic) IBOutlet UILabel *categoriesLabel;
@property (weak, nonatomic) IBOutlet UIView *priceRangeView;
@property (nonatomic) CGSize distanceLabelSize;
@property (nonatomic) CGFloat distanceLabelWidth;
@end
我在想比在每个滚动细胞的细胞兑美元imageview的,我想知道如何避免这种情况。如果有人可以建议我一个更好的方法?
试试这个@Barzull [cell.contentView addSubview:IMG] http://stackoverflow.com/a/26881504/3767017 – 2014-11-21 09:26:23
感谢,但cell.priceRangeView是一个UIView,我试图用你的建议,但它再次叠加。 – Jeffrey 2014-11-21 09:37:20
只是一个建议,当你制作自定义单元格并为其制作UITableViewCell子类时,为什么你要为其单元格数据创建另一个类,则应该将所有数据填充到同一个子类中 (因为我明白看到您的代码) – 2014-11-21 11:50:56