委托方法不起作用

Delegate Method not Working

我正在尝试为我的按钮实现委托方法...我想我做的一切都正确但不明白为什么我不能让它工作...我的按钮不响应任何命令看起来死了…………

我的按钮位于 ViewController "B" 中,它要执行的功能位于 ViewController "A"

这是我的代码

viewControllerB.h

@protocol UNI_TableLoginDelegate <NSObject>
-(void)showPassw;

@end

@interface viewControllerB : UITableViewController
@property (nonatomic, weak) id <UNI_TableLoginDelegate> delegate;
@end

viewControllerB.m(这里我通过故事板连接了动作按钮)

@implementation viewControllerB
@synthesize  delegate;


- (void)viewDidLoad {
    [super viewDidLoad];

}
- (IBAction)showReset:(id)sender {
    [delegate showPassw];    
}

viewControllerA.m

#import "viewControllerB.h"

    @interface viewControllerA () <UNI_TableLoginDelegate>

    - (void)viewDidLoad {
        [super viewDidLoad];

        viewControllerB *tableLogin = [[viewControllerB alloc] init];
        tableLogin.delegate = self;

    }

    //Delegate Method
    -(void)showPassw {

        if (containerTable.frame.origin.y == 56) {
            NSLog(@"ssss");
        }

        else {
            NSLog(@"hdhdh");
        }
    }

您需要在 ViewController A 中设置委托。

假设您有这个方法在关闭 ViewController A:

之前立即调用
-(void)dismissThisController{

 // you need to set the delegate value
 [self.delegate yourDelegateMethod:withValueYouWantToSend];

 [self dismissViewControllerAnimated:YES completion:^{

}];
}

在你的视图控制器 B 中,你有这个委托方法:

#pragma mark ViewController A delegate
-(void)yourDelegateMethod:(someType)value{
//receive your delegate value here
    }