//AddSideBarProtocol.h
@protocol AddSideBarProtocol <NSObject>
- (IBAction)barButtonTapped:(id)sender;
@end
我正在创建上述协议以在我的所有视图控制器中使用。我对此协议的实现如下:
//AddVehicleViewController.m
- (IBAction)barButtonTapped:(id)sender{
[self.view endEditing:YES];
[lblToolBarTitle setText:@"Vehicle Management"];
tblViewSideBar = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 200, self.view.frame.size.height-44)];
tblViewSideBar.delegate = self;
tblViewSideBar.dataSource = self;
tblViewSideBar.separatorStyle = UITableViewCellSeparatorStyleNone;
[tblViewSideBar setBackgroundColor:[UIColor lightGrayColor]];
btnToClose = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[btnToClose setBackgroundColor:[UIColor clearColor]];
[btnToClose addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
addSideBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 44, 200, self.view.frame.size.height)];
[addSideBarView setBackgroundColor:[UIColor blackColor]];
addSideBarView.frame = CGRectMake(-200, 44, 200, self.view.frame.size.height);
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
addSideBarView.frame = CGRectMake(0, 44, 200, self.view.frame.size.height);
}
completion:nil];
[self.view addSubview:btnToClose];
[self.view addSubview:addSideBarView];
[addSideBarView addSubview:tblViewSideBar];
}
我正在使用以下代码行从另一个名为“MaintenanceViewControlle”的视图控制器调用协议:
AddVehicleViewController *addVehicle = [[AddVehicleViewController alloc] init];
id <AddSideBarProtocol> addSide;
addSide = addVehicle;
[addSide barButtonTapped:sender];
但是这个协议不能正常运行,所以我缺少什么??