2012-02-15 29 views
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,所以我想象這個問題來自我如何實現數據源協議。

回答

0

這是一個不好的問題,其答案不在於發佈的代碼中。問題是,我沒有將視圖控制器設置爲委託。我補充說:self._equationView.dataSource=self;問題解決了。