Skip navigation.
 
mlRe: Understanding the inner workings: getting to know how functions are called
FROM : Mattias Arrelid
DATE : Tue Jan 22 20:34:17 2008

On 22 jan 2008, at 17.26, Kyle Sluder wrote:

> On 1/22/08, Mattias Arrelid <<email_removed>> 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.)