【发布时间】:2014-01-21 17:44:12
【问题描述】:
我正在创建一个绘制统计信息的 UIView(实际上是 contentView 中的子视图之一)。
这个视图设置在 UITableview 的每个单元格中。
我配置单元格,在:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellConstant = @"constant";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellConstant forIndexPath:indexPath];
SCHGraphicView *statView = (SCHGraphicView *)[cell viewWithTag:TAG_STAT_GRAPH];
[statView setStatValues:[self.listOfListWithValues objectAtIndex:indexPath.row] andBase:10 andColorBar:[UIColor whiteColor]];
return cell;
}
这是 drawRect 方法,现在在测试模式下我只绘制一个值。
- (void)drawRect:(CGRect)rect
{
CGFloat heightCalculate = ([(NSNumber *)[self.statValues objectAtIndex:1]intValue] *self.frame.size.height) / self.base;
//We create the path
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0,self.frame.size.height - heightCalculate, self.frame.size.width, heightCalculate)];
path.lineWidth = 0;
[self.barColor setFill];
CGContextRef context = UIGraphicsGetCurrentContext();
//We saved the context
CGContextSaveGState(context);
[path fill];
//Restore the contex
CGContextRestoreGState(context);
}
虽然我每次都在cellForRowAtIndexPath: 中修改统计值,但这些值不会调用 [UIView setNeedDisplay] 所以我不会每次都重绘它,因为每个单元格中的统计永远不会改变,但如果是不同的统计您比较单元格之间的统计数据。
问题是当我滚动并返回第一个单元格时,它不包含最初绘制的统计数据。
我实现这一目标的唯一方法是每次重绘cellForRowAtIndexPath 中的统计信息
但我认为在第一次绘制视图时保存了预览,这用于提高性能,如果您调用 [UIView setNeedDisplay] 视图将再次重绘。
有什么想法吗?
非常感谢
【问题讨论】:
标签: ios objective-c uiview ios7