我正在尝试将 KGModal 中的代表连接到 MainView,但它不起作用。基本上我在KGModal (Github)中显示 SecondViewController ,当关闭 KGModal 视图时,我希望 MainView 通过委托知道这一点。有任何想法吗?(抱歉解释不好)。无法让它工作。
KGMdal.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];
}
主视图.h
@interface MainView : UIViewController <KGModalDelegate>
@property(weak) id<KGModalDelegate> delegate;
主视图.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];
}