委托方法不工作
我想为我的按钮实现一个委托方法...我想我做的一切正确,但不明白为什么我不能使它工作...我的按钮不响应任何命令看起来死了......委托方法不工作
我的按钮位于视图控制器“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一个
假设你有这种方法,驳回的ViewController答:
-(void)dismissThisController{
// you need to set the delegate value
[self.delegate yourDelegateMethod:withValueYouWantToSend];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
,并在您的视图控制器B,你有这样的委托方法:
我理解你描述的方式,我认为它与我在代码中使用的是一样的吗?所有你必须做的按钮,它位于viewController B,是在viewController代码A viewController A =要执行的代码 viewController B =哪里是按钮 – kAiN
你能告诉我你是如何呈现查看控制器B? –
我的意思是,你如何从A航行到B? –
哪里的'价值delegate'设置?使用'@ synthesize'多年来一直不是很好的做法,它不是必需的,带有下划线“_”的实例变量将自动生成。最佳做法是不直接使用属性iVars,而是使用'self.','[self.delegate showPassw];' – zaph
你怎样调用viewCntoller B?你如何设置代表?你在使用performSegue方法吗? –
我删除了thesyntesize并采用self.delegate作为你的建议,但是当我使用按钮仍然没有得到任何动作 – kAiN