delegate

作者: 曾柏超 | 来源:发表于2018-06-13 14:15 被阅读1次

#import <UIKit/UIKit.h>

@class ModalViewController;

@protocol ModalViewControllerDelegate <NSObject>
@optional

-(void)modalViewController:(ModalViewController *)modalVc sendValue:(NSString *)value;
@end


@interface ModalViewController : UIViewController
@property (nonatomic,weak) id<ModalViewControllerDelegate> delegate;
@end


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    
    if ([_delegate respondsToSelector:@selector(modalViewController:sendValue:)]) {
        [_delegate modalViewController:self sendValue:@"123"];
    }
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
#import "ViewController.h"
#import "ModalViewController.h"
@interface ViewController ()<ModalViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    
    ModalViewController *vc = [ModalViewController new];
    vc.delegate = self;
    [self presentViewController:vc animated:YES completion:nil];
    
}

-(void)modalViewController:(ModalViewController *)modalVc sendValue:(NSString *)value
{
    
    NSLog(@"%@",value);
    
}

相关文章

网友评论

      本文标题:delegate

      本文链接:https://www.haomeiwen.com/subject/tnyjeftx.html