views:

36

answers:

1

Hi everyone,

im trying to implement some behaviors when a mapview element scrolls... by coding a delegate for the scrollview inside of a mapview.

so, right now, i got a pointer to the scroll view used by the map view in my code.

however, i wish to set the delegate of this scroll view inside the map view, but the issue is that the mapview already sets up a default delegate for this scroll view inside the map view.

can i make my delegate implement all of the messages of the protocol, explicitly sending them to the mapview's default delegate while also implementing my own behaviors?

how else can i go about adding my own delegate behavior, to an already existing default delegate....?

thanks everyone, michael

+1  A: 

You could just get the existing delegate and save a reference for yourself:

origDelegate = [theView delegate];

And then set the object you want as the delegate:

[theView setDelegate:self];

Then when getting a delegate message, call the same method on origDelegate, modify the response if you want to (or if necessary), and then return the modified response:

- (BOOL)shouldViewDoSomething:(id)theView
{
    BOOL result = [origDelegate shouldViewDoSomething:theView];

    if (decision1)
    {
        result = !result;
    }

    return result;
}
Carl Norum
yea this is what ive done. wish there was a more elegant solution.
Michael Xu
@Michael, you could try making an `NSProxy` subclass. I don't know if that's worth it, though.
Carl Norum