ghiboz
ghiboz

Reputation: 8003

iphone make personal delegate

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???

Upvotes: 0

Views: 84

Answers (1)

Jeff Kelley
Jeff Kelley

Reputation: 19071

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.

Upvotes: 2

Related Questions