簡體   English   中英

DrawRect永遠不會被調用

[英]DrawRect never being called

我將此代碼放在我的應用中:

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

}

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

我在NSLog上得到了一堆測試1(因為這是一個UITableViewCell),但是在任何時候都沒有測試2。

我在此處下載了示例項目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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM