Andrew
Andrew

Reputation: 16051

DrawRect never being called

I put this code in my app:

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

}

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

I get a bunch of Test 1s on the NSLog (because this is a UITableViewCell), but no Test 2s at any point.

Upvotes: 0

Views: 567

Answers (1)

Kibitz503
Kibitz503

Reputation: 867

I downloaded the sample project TableViewSuite (CustomTableViewCell project) here: https://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html I was able to add your log statement into the TimeZoneCell class and was able to get output. Taking a look at this might help answer your question?

#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

Upvotes: 3

Related Questions