Пользовательский метод делегата не работает в объективе - c - PullRequest
0 голосов
/ 06 января 2020

// 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");
}

, но метод делегата не вызывается при выталкивании UserProfileForm. Я не знаю, почему это не стрельба. Я пробовал NSNotifications, и он тоже не срабатывал.

1 Ответ

0 голосов
/ 06 января 2020

Я только что попробовал ваш код, и он работал нормально. Единственное, что я изменил, было в конце viewDidLoad() из ShopProfileController Я поставил следующую строку:

[userProfileForm endFlow:self];

Таким образом, ваша реализация делегата должна быть правильной. Установите точку останова в вашем endFlow() методе, держу пари, что его не вызывают.

...