我正在尝试将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];
}
答案 0 :(得分:1)
问题解决了。我将委托设置为KGModal的不同实例。
KGModal *kgm = [KGModal sharedInstance];
kgm.delegates = self;
[kgm showWithContentView:view2.view andAnimated:YES];
感谢Hot Licks!