在视图之间连接委托的问题

时间:2012-12-16 01:08:23

标签: iphone ios delegates

我正在尝试将KGModal中的委托连接到MainView,但它不起作用。基本上我在KGModal (Github)中显示SecondViewController,当解除KGModal视图时,我希望MainView通过委托知道。有任何想法吗? (抱歉不好解释)。无法让它发挥作用。

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];
}

1 个答案:

答案 0 :(得分:1)

问题解决了。我将委托设置为KGModal的不同实例。

KGModal *kgm = [KGModal sharedInstance];

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

感谢Hot Licks!