我把这段代码放在我的应用中:
-(void)setup {
[self setNeedsDisplay];
NSLog(@"Test 1");
}
-(void)drawRect:(CGRect)rect {
NSLog(@"Test 2");
}
我在NSLog上获得了一堆测试1(因为这是一个UITableViewCell),但在任何时候都没有测试2。
答案 0 :(得分: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