Christoffer
Christoffer

Reputation: 1647

Problems wiring up delegate between views

I'm trying to wire up the delegate in KGModal to MainView, but it doesnt work. Basically I show SecondViewController in KGModal (Github), and when dismissing the KGModal view i want the MainView to know that through the delegate. Any ideas? (sorry for bad explanation). Can't get it to work.

KGModal.h

@class KGModal;
@protocol KGModalDelegate <NSObject>
- (void)modalControllerDidFinish:(KGModal *)controller;
@end

@interface KGModal : NSObject {
    UIButton *dismissButton;
}

@property (weak, nonatomic) id <KGModalDelegate> delegate;

KGModal.m

-(void)dismissButtonPressed:(id)sender {
        [self.delegate modalControllerDidFinish:self];
        [self hideAnimated:self.animateWhenDismissed];   
}    

MainView.h

@interface MainView : UIViewController <KGModalDelegate> 

@property(weak) id<KGModalDelegate> delegate;

MainView.m

- (void)modalControllerDidFinish:(KGModal *)controller{ 
    NSLog(@"Dismissed.");
}

-(IBAction)modalShowing {

SecondViewController *view2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

        KGModal *kg = [[KGModal alloc] init];
        kg.delegate = self;

        [[KGModal sharedInstance] showWithContentView:view2.view andAnimated:YES];
}

Upvotes: 0

Views: 250

Answers (1)

Christoffer
Christoffer

Reputation: 1647

Problem solved. I set the delegate to different instances of KGModal.

KGModal *kgm = [KGModal sharedInstance];

kgm.delegates = self;
[kgm showWithContentView:view2.view andAnimated:YES];

Thanks to Hot Licks!

Upvotes: 1

Related Questions