kAiN
kAiN

Reputation: 2773

Delegate Method not Working

I'm trying to implement a delegate method for my button ... I think I did everything correctly but do not understand why I can not make it work ... My button does not respond to any commands looks dead ... ...

My button is located in the ViewController "B" and the function it has to perform is located in the ViewController "A"

This is my code

viewControllerB.h

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

@end

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

viewControllerB.m (here I connected the action button via my storyboard)

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

Upvotes: 0

Views: 59

Answers (1)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

You need to set the delegate in your ViewController A.

Let's say you have this method that calls right before dismissing the ViewController A:

-(void)dismissThisController{

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

 [self dismissViewControllerAnimated:YES completion:^{

}];
}

and in your View Controller B, you have this delegate method:

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

Upvotes: 1

Related Questions