iosobjective-cxcode10.1

Custom Delegate method not working in objective-c


// userprofileform.h(viewcontroller)

@class UserProfileForm;             
@protocol UserProfileFormDelegate <NSObject>
- (void) UserProfileFormDelegateReload: (UserProfileForm *) sender;

@end

@interface UserProfileForm : OTSFormViewController <UIActionSheetDelegate>
@property(nonatomic,assign) id <UserProfileFormDelegate> delegate;

@end

//userprofileform.m

#import "UserProfileForm.h"

@implementation UserProfileForm

- (void)endFlow:(id)sender {
     [self.delegate UserProfileFormDelegateReload:self];
     [self.navigationController popViewControllerAnimated:YES];
}

//shopprofilecontroller.h

#import "UserProfileForm.h"

@interface ShopProfileController : OTSViewController <UserProfileFormDelegate>

@end

//shoprofilecontroller.m

@implementation ShopProfileController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationItem.title = @"Business";

    UserProfileForm * userProfileForm = [[UserProfileForm alloc] init];
    userProfileForm.delegate = self;
}

-(void)UserProfileFormDelegateReload:(UserProfileForm *)sender{
    NSLog(@"delegates fired");
}

but the delegate method is not called upon popping the UserProfileForm. I don't know why is it not firing. I have tried NSNotifications and it did not fire too.


Solution

  • I just tried your code and it worked fine. The only thing I changed was at the end of viewDidLoad() of ShopProfileController I put the following line:

    [userProfileForm endFlow:self];
    

    So your delegate implementation should be correct. Set a breakpoint within your endFlow() method, I bet its not getting called.