标签:
个人理解(估计,半年一年后,在看到这篇文章的时候,会觉得,当时真的弱爆了)
ViewWithButtons.h部分的代码。
@protocol ViewWithBuutonsDelegate<NSObject>
@required
-(void)buttonClickedWithTag:(NSInteger)tag;
@end
@interface ViewWithButtons : UIView
@property(nonatomic)id <ViewWithBuutonsDelegate> delegate;
@end
- (IBAction)buttonClick:(UIButton *)sender {
if ([self.delegate respondsToSelector:@selector(buttonClickedWithTag:)]) {
[self.delegate buttonClickedWithTag:sender.tag];
}
}
#import "ViewController.h"
#import "ViewWithButtons.h"
@interface ViewController ()<ViewWithBuutonsDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
ViewWithButtons *view = [[[NSBundle mainBundle]loadNibNamed:@"ViewWithButtons" owner:self options:nil]lastObject];
view.delegate = self;
[self.view addSubview:view];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)buttonClickedWithTag:(NSInteger)tag{
NSLog(@"%lu",tag);
}
标签:
原文地址:http://www.cnblogs.com/mudy/p/4818764.html