我正在尝试为我的按钮实现委托方法...我认为我做的一切都正确但不明白为什么我不能使它工作...我的按钮没有响应任何看起来死的命令.. ......
我的按钮位于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");
}
}
答案 0 :(得分:1)
您需要在ViewController A中设置委托。
让我们假设您在解除ViewController A之前调用此方法:
-(void)dismissThisController{
// you need to set the delegate value
[self.delegate yourDelegateMethod:withValueYouWantToSend];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
并且在View Controller B中,您有此委托方法:
#pragma mark ViewController A delegate
-(void)yourDelegateMethod:(someType)value{
//receive your delegate value here
}