[英]How to change method dispatch table in objective-c?
As a practical example, in UIView, drawRect is called when setNeedsDisplay is set. 作为一个实际示例,在UIView中,设置setNeedsDisplay时将调用drawRect。 I want a different drawRect routine to be called for the first time vs. the subsequent update.
我希望第一次调用不同的drawRect例程,而不是随后的更新。 So for example, I want drawRect to call drawRectFirstTime for the first time and drawRect to call drawRectSubsequentUpdate for subsequent setNeedsDisplay.
因此,例如,我希望drawRect首次调用drawRectFirstTime,而drawRect则为后续的setNeedsDisplay调用drawRectSubsequentUpdate。
How should this be done in Objective-C? 在Objective-C中应该如何完成?
From top of my head: 从我的头顶:
- (void)drawRect:(NSRect)rect
{
static BOOL first = YES;
if (first == NO)
{
[self drawRectSubsequentUpdate:rect];
} else {
[self drawRectFirstTime:rect];
first = NO
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.