开发者

how do i add two delegates to a ui element at run time?

开发者 https://www.devze.com 2022-12-23 17:46 出处:网络
im trying to implement some behaviors when a mapview element scrolls... by coding a delegate for the scrollview inside of a mapview.

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 dele开发者_StackOverflow中文版gate 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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消