简体   繁体   English

自定义委托方法在objective-c 中不起作用

[英]Custom Delegate method not working in objective-c

// userprofileform.h(viewcontroller) // 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 //userprofileform.m

#import "UserProfileForm.h"

@implementation UserProfileForm

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

//shopprofilecontroller.h //shopprofilecontroller.h

#import "UserProfileForm.h"

@interface ShopProfileController : OTSViewController <UserProfileFormDelegate>

@end

//shoprofilecontroller.m //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.但是在弹出 UserProfileForm 时不会调用委托方法。 I don't know why is it not firing.不知道为什么打不开I have tried NSNotifications and it did not fire too.我尝试过 NSNotifications,但它也没有触发。

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:我唯一改变的是在ShopProfileControllerviewDidLoad()ShopProfileController我放了以下行:

[userProfileForm endFlow:self];

So your delegate implementation should be correct.所以你的委托实现应该是正确的。 Set a breakpoint within your endFlow() method, I bet its not getting called.在你的endFlow()方法中设置一个断点,我敢打赌它不会被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM