0
數組繪製字符串我試圖從drawRect中數組繪製字符串,但他們沒有被繪製。所述的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];
}
}
數據源協議在視圖中的控制器執行。數組中的對象是一個包含字符串和繪製該字符串的點的類。我使用NSLog確保對象實際上正確地放入數組(它們是)。此外,還有一行將setNeedsDisplay發送到視圖。當我運行這段代碼時,它會出現空白,所以我不確定發生了什麼問題。這是我第一次嘗試使用從應用程序內輸入的數據來運行drawRect,所以我想象這個問題來自我如何實現數據源協議。