2012-05-25 44 views
0

我把這個代碼在我的應用程序:drawRect中從來沒有被稱爲

-(void)setup { 
    [self setNeedsDisplay]; 
    NSLog(@"Test 1"); 

} 

-(void)drawRect:(CGRect)rect { 
    NSLog(@"Test 2"); 
} 

我收到了一堆的NSLog的測試中1的(因爲這是一個UITableViewCell),但在任何時候任何測試2S。

+0

你應該向我們展示代碼或解釋你如何實例化和使用類。它是一個班級還是一個類別? ... –

+0

這是一個自定義的UITableView。 – Andrew

+0

我有框架高度設置爲0;顯然這意味着它不稱之爲不正確。 – Andrew

回答

3

我在這裏下載了示例項目TableViewSuite(CustomTableViewCell項目):https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html 我能夠將日誌語句添加到TimeZoneCell類中並能夠獲取輸出。看看這可能有助於回答你的問題?

#import "TimeZoneCell.h" 
#import "TimeZoneWrapper.h" 
#import "TimeZoneView.h" 
#import "CustomTableViewCellAppDelegate.h" 


@implementation TimeZoneCell 

@synthesize timeZoneView; 


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) { 

     // Create a time zone view and add it as a subview of self's contentView. 
     CGRect tzvFrame = CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, self.contentView.bounds.size.height); 
     timeZoneView = [[TimeZoneView alloc] initWithFrame:tzvFrame]; 
     timeZoneView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.contentView addSubview:timeZoneView]; 
    } 
    return self; 
} 
-(void)drawRect:(CGRect)rect { 
    NSLog(@"Test 2"); 
} 

- (void)setTimeZoneWrapper:(TimeZoneWrapper *)newTimeZoneWrapper { 
    // Pass the time zone wrapper to the view 
    timeZoneView.timeZoneWrapper = newTimeZoneWrapper; 
} 


- (void)redisplay { 
    [timeZoneView setNeedsDisplay]; 
} 


- (void)dealloc { 
    [timeZoneView release]; 
    [super dealloc]; 
} 


@end