Re: Understanding the inner workings: getting to know how functions are called
Re: Understanding the inner workings: getting to know how functions are called
- Subject: Re: Understanding the inner workings: getting to know how functions are called
- From: Mattias Arrelid <email@hidden>
- Date: Tue, 22 Jan 2008 20:34:17 +0100
On 22 jan 2008, at 17.26, Kyle Sluder wrote:
On 1/22/08, Mattias Arrelid <email@hidden> wrote:
Could anyone point me in the right direction here? I'm open to all
suggestions...
I'd create a subclass of NSProxy, override
-methodSignatureForSelector: and -forwardInvocation: appropriately
(perhaps putting a breakpoint in -forwardInvocation: that prints a
backtrace and auto-continues), and return an instance of this from
your real object's -init method. If you do it right, clients of your
class should be none the wiser.
That's an interesting approach (what I'm trying to achieve here is a
better understanding of how NSScroller and NSScrollView interact).
Trying your approach, I've subclassed and NSScroller (MAScroller). In
my test view, right after I create my scroll view, I have these two
lines:
[scrollView setHorizontalScroller:[[SPScroller alloc] initWithFrame:
[[scrollView horizontalScroller] frame]]];
[scrollView setVerticalScroller:[[SPScroller alloc] initWithFrame:
[[scrollView verticalScroller] frame]]];
(Let's not bother with the memory not being autoreleased in the two
above lines).
Now this works perfectly; the scroll view do get MAScrollers as
scrollers (I've put a dummy drawRect: in SPScroller, it draws blue in
the entire rect passed to it. Once confirmed, I removed this).
That done, I subclass NSProxy (calling it MAProxy). In its interface,
I declare:
"id realObject"
That will be a pointer to the object i "proxying" for. I also put this
in the implementation part:
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
NSLog(@"methodSignatureForSelector: %@",
NSStringFromSelector(aSelector));
return [realObject methodSignatureForSelector:aSelector];
}
Now, lets assume I would like to know more about the calling order
(regarding the interaction between NSScrollView and MAScroller). In
the "- (id)initWithFrame:(NSRect)frameRect" of MAScroller, I return an
instance of MAProxy (with "realObject" set to the instance of
MAScroller that should have been returned). Now, if I watch the
console, I get various calls like this:
2008-01-22 20:25:27.088 ScrollVew[52909:10b]
methodSignatureForSelector: controlSize
2008-01-22 20:25:27.089 ScrollVew[52909:10b]
methodSignatureForSelector: setDoubleValue:
2008-01-22 20:25:27.089 ScrollVew[52909:10b]
methodSignatureForSelector: setKnobProportion:
2008-01-22 20:25:27.090 ScrollVew[52909:10b]
methodSignatureForSelector: setDoubleValue:
2008-01-22 20:25:27.090 ScrollVew[52909:10b]
methodSignatureForSelector: setKnobProportion:
What I do _not_ get is calls to e.g. drawRect: and similar (for
MAScroller) (that I _know_ have to be called for something to get
drawn). It seems like I only get some of the NSScroller calls through
my proxy object...? :/
Do you (or someone else who is wise enough) have any idea why this
might be the case?
(Many thanks to you Kyle, Bill B, Alastair H and Jeff J for your
input; I thought I'd try this approach first, as it seemed easiest at
the moment.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden