【发布时间】:2012-02-15 01:08:12
【问题描述】:
我正在尝试从 drawrect 中的数组中绘制字符串,但它们没有被绘制。 drawRect 代码如下所示
- (void)drawRect:(CGRect)rect
{
UIFont *font = [UIFont systemFontOfSize:14];
CGRect ourRect;
ourRect.origin.x=ourRect.origin.y=20.0;
ourRect.size.width=130.0;
ourRect.size.height= 100.0;
CGPoint pointer;
pointer.x=pointer.y=20;
NSString*string;
string=[[NSString alloc] init];
[string drawAtPoint:pointer withFont:font];
NSMutableArray * whatShouldIDraw=[[NSMutableArray alloc]init];
whatShouldIDraw=[self.dataSource whatToDraw:self];
NSUInteger i;
for (i=0; i<[whatShouldIDraw count]; i++) {
[[[whatShouldIDraw objectAtIndex:i] equationBit] drawAtPoint:[[whatShouldIDraw objectAtIndex:i]drawPoint] withFont:font];
}
}
dataSource 协议在视图的控制器中实现。数组中的对象属于一个类,该类包含一个字符串和一个绘制该字符串的点。我使用 NSLog 来确保对象实际上被正确地放入数组中(它们是)。此外,还有一行将 setNeedsDisplay 发送到视图。当我运行这段代码时,它会出现空白,所以我不确定出了什么问题。这是我第一次尝试让 drawRect 使用从应用程序中输入的数据运行,所以我想问题来自我如何实现数据源协议。
【问题讨论】: