项目中的 35 个头文件之一(由其他开发人员移交给我;所有这些文件都包含相同的委托声明)
@interface ActivityDetailsCN : UIViewController <NSXMLParserDelegate,
AccountStatusDelegate, AccountTypeDelegate, DirectionDelegate, RecipientDelegate,
PriorityDelegate, DurationDelegate, CurrencyDelegate, OppTypeDelegate,
OppCategoryDelegate, DatePickerDelegate, SalutationDelegate, DepartmentDelegate,
LeadTypeDelegate, OwnershipDelegate, MailingDelegate, SourceDelegate,
StateDelegate, CommentsDelegate, CityDelegate, ZipCodeDelegate>
{
//Declaration of iVars goes here...
}
此处声明的所有委托都包含相同的功能。甚至他们的定义也是如此。这些委托中的每一个都在各自的ViewController
头文件之前声明如下:
@protocol AccountStatusDelegate <NSObject>
- (void)cancelTapped;
- (void)doneTapped;
- (void)selectTapped:(NSString *)string;
@end
@interface AccountStatusVC : UIViewController <NSXMLParserDelegate> {
}
@property (unsafe_unretained) id <AccountStatusDelegate> delegate;
cancelTapped 的实现:
- (void)cancelTapped {
[objPopOver dismissPopoverAnimated:YES];
}
cancelTapped 的实现:
- (void)doneTapped {
[tblView reloadData];
[objPopOver dismissPopoverAnimated:YES];
}
cancelTapped 的实现:
- (void)selectTapped:(NSString *)string
{
if ([string isEqualToString:@"US"])
isTextField = FALSE;
else if([string isEqualToString:@"Other"]) {
appDelegate.strCountry = @"";
isTextField = TRUE;
}
[tblView reloadData];
[objPopOver dismissPopoverAnimated:YES];
}
现在,提出问题:我不想在每一堂课中都重复它(就像现在一样);我想以更清洁的方式制作,有没有可能的解决方案?