1.代理类
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol InputViewDelegate <NSObject>
-(void)btnClick:(UIButton*)sender textNumer:(NSString*)str1 textNumber:(NSString*)str2;
@end
@interface InputView : UIView
@property (nonatomic,weak) id<InputViewDelegate> delegate;
@end
NS_ASSUME_NONNULL_END
#import "InputView.h"
@interface InputView()
@property (weak, nonatomic) IBOutlet UITextField *OneTextField;
@property (weak, nonatomic) IBOutlet UITextField *TwoTextField;
@end
@implementation InputView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (IBAction)btnClick:(UIButton *)sender {
if ([self.delegate respondsToSelector:@selector(btnClick: textNumer: textNumber:)]) {
// 调用代理对象的登录方法,代理对象去实现登录方法
[self.delegate btnClick:sender textNumer:self.OneTextField.text textNumber:self.TwoTextField.text];
}
}
@end
2.使用类
#import "PlanCtl.h"
@interface PlanCtl ()<InputViewDelegate>
@property (nonatomic,strong) InputView *inputView;
@end
@implementation PlanCtl
-(__kindof UIView *)inputView
{
if (_inputView == nil) {
_inputView = [[[NSBundle mainBundle] loadNibNamed:@"InputView" owner:nil options:nil] lastObject];
_inputView.delegate = self;
}
return _inputView;
}
// InputViewDelegate
-(void)btnClick:(UIButton *)sender textNumer:(NSString *)str1 textNumber:(NSString *)str2
{
}
@end
网友评论