Reputation: 175
I have a ConfirmClaimViewcontroller.h
which defines a delegate as:
@protocol ClaimConfirmedDelegate<NSObject>
@required
- (void) claimConfirmedDelegate : (NSInteger) tag;
@end
@interface ConfirmClaimControllerViewController : UIViewController{
id <ClaimConfirmedDelegate> delegate;
}
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withTag:(NSInteger)tag;
@property(nonatomic,assign)id delegate;
@end
I define the delegate in ClaimViewController.m
:
- (void) claimConfirmedDelegate:(NSInteger)tag{
NSLog(@"Delegate called");
}
I call the ConfirmClaimViewController
as below ( its a popup) :
ConfirmClaimControllerViewController *confirmClaimController=[[ConfirmClaimControllerViewController alloc] initWithNibName:@"ConfirmClaim" bundle:nil withTag:sender.view.tag];
confirmClaimController.delegate = self;
[self.view addSubview:confirmClaimController.view];
[confirmClaimController didMoveToParentViewController:self];
[self addChildViewController:confirmClaimController];
The popup has two buttons. One one of the button is clicked, this code is called :
if([self.delegate respondsToSelector:@selector(claimConfirmed:)])
{
[self.delegate claimConfirmedDelegate:self.tagId];
}
[self.view removeFromSuperview];
[self removeFromParentViewController];
This is supposed to call the delegate method and then remove the child from view. Child gets removed but delegate is never called. I'm new to this , any help would be appreciated.
Upvotes: 0
Views: 77
Reputation: 119031
This line:
if([self.delegate respondsToSelector:@selector(claimConfirmed:)])
Should be:
if([self.delegate respondsToSelector:@selector(claimConfirmedDelegate:)])
Upvotes: 2