Have you seen this

http://katidev.com/blog/2008/04/17/nsviewcontroller-the-new-c-in-mvc-pt-2-of-3/

and this thread

http://www.cocoabuilder.com/archive/message/cocoa/2008/3/19/201743

All of this is covered, with automatic insertion of view controllers into the responder chain.

If you want to set up the view controller as the next responder of the view (not done in the above) then you might be better with this code (thanks, Ali Lalani)

#import "MyViewController.h"


@implementation MyViewController
- (void)loadView;
{
    [super loadView];

[[self view] addObserver:self forKeyPath:@"nextResponder" options:0 context:NULL];
}

- (void)dealloc;
{
    [[self view] removeObserver:self forKeyPath:@"nextResponder"];
    [super dealloc];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject: (id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"nextResponder"])
    {
// when we get called due to setting next responder as ourselves we ignore it (could also unobserve right before and re- observe right after...)
        if ([[self view] nextResponder] != self)
        {
            [self setNextResponder:[[self view] nextResponder]];
            [[self view] setNextResponder:self];
        }
    }
    else
    {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}
@end


In this way the view controller will 'jump' in whenever the view's nextResponder is set.

HTH

Jon

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to