我将 UIView 放在 UITableViewCell 上,用于绘制自定义视图,例如简单的图表视图。然后,一旦有新数据出现,我就会尝试刷新 UIView。但它不起作用。我想知道我这样做的方式是否正确。或者还有另一种刷新 UIView 的方法。
Here is code fragment.
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//
graphView = [[ChartView alloc] initWithFrame:CGRectMake(290, 5, 18, 36)];
[cell.contentView addSubview:graphView];
[graphView release];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 105.0, 45.0)];
[cell.contentView addSubview:nameLabel];
[StockNameLabel release];
}
....
..
return cell;
}
- (void)realTimeData:(NSMutableDictionary *)data { <--- its a call back method
NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [m_InterestTableView cellForRowAtIndexPath:cellIndexPath];
ChartView *chartView = (ChartView*)[cell.contentView.subviews objectAtIndex:0];
[chartView initWithPrices:sPrice withcPrice:cPrice withlPrice:lPrice withhPrice:hPrice];
}
ChartView
- (void) refreshScreen{
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
//get graphic context
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSetLineWidth(context,2.0f);
CGContextSetShouldAntialias(context, NO);
CGContextMoveToPoint(context,x1,y1);
CGContextAddLineToPoint(context,x2, y2);
[RGB(r,g, b) set];
CGContextStrokePath(context);
CGContextAddRect(context,fillArea);
[RGB(r, g, b) set];
CGContextFillPath(context);
}