views:

27

answers:

1

Hi all! I have this problem.... in my viewcontroller.h I defined my class like this:

myClass* iR;

and after:

@property (nonatomic,retain) IBOutlet myClass* iR;

into myClass.h I added this:

@protocol myClassDelegate <NSObject>
-(void) didLogon:(bool)isLogged;
@end

and after:

@property (nonatomic, assign) id<myClassDelegate> delegate;

now, into my class, in the connectionDidFinishLoading method ( I used a nsurlconnection to retrieve the login data I added this:

[self.delegate didLogon:true];

into myviewcontroller.h:

<myClassDelegate>

and into myviewcontroller.m:

-(void)didLogon:(bool)isLogged{
...
}

but the program go inside the self.delegate didLogon but into myviewcontroller.m didn't go... did you understand why???

+2  A: 

Where are you assigning the delegate? You need something like this:

MyViewController *viewController = [[MyViewController alloc] init];
self.delegate = viewController;

Just to be safe, when you call delegate methods, call them like this:

if ([self.delegate respondsToSelector:@selector(didLogon:)]) {
    [self.delegate didLogon:YES];
}

That way, if the delegate doesn't support that method, your program won't crash when it doesn't recognize that selector.

Jeff Kelley
thanks jeff very useful this , also the check for the delegate...
ghiboz