我有所有的子類的單一方法我想提供一個父視圖控制器:IOS的UIViewController繼承引發的重複符號錯誤
#import "GAViewController.h"
@interface GAViewController()<UITextFieldDelegate>
@end
@implementation GAViewController
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
@end
我有一個看起來像這樣的寄存器視圖控制器:
//.h
#import <UIKit/UIKit.h>
#import "GAViewController.h"
#import "GAViewController.m"
@interface GARegisterViewController : GAViewController
@end
//.m
#import "GARegisterViewController.h"
@interface GARegisterViewController()<UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField;
@property (weak, nonatomic) IBOutlet UISegmentedControl *genderSegmentedContoller;
@end
@implementation GARegisterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self makeTextFieldDelegates];
}
- (void)makeTextFieldDelegates{
[self.userNameTextField setDelegate:self];
[self.passwordTextField setDelegate:self];
[self.firstNameTextField setDelegate:self];
[self.lastNameTextField setDelegate:self];
[self.phoneNumberTextField setDelegate:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
這是我收到的錯誤:
有誰知道我可以修復上面的錯誤?或者使用textFieldShoudlReturn
方法正確創建一個父類,以便我不必在所有視圖中都包含該類。
謝謝!
據我所見,我看不到你遇到的錯誤。 –
添加圖像到通信 – Atma
我導入.m,因爲它包含textfieldshouldreturn方法,它也導入.h文件 – Atma