gpt4 book ai didi

ios uiviewcontroller继承抛出重复符号错误

转载 作者:行者123 更新时间:2023-12-01 18:58:49 25 4
gpt4 key购买 nike

我有一个父 View Controller ,它有一个我希望所有子类都可以使用的方法:

#import "GAViewController.h"

@interface GAViewController ()<UITextFieldDelegate>

@end

@implementation GAViewController


#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}


@end

我有一个看起来像这样的注册 View Controller :
//.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

这是我收到的错误:
enter image description here
enter image description here

有谁知道我可以修复上面的错误?或者使用 textFieldShoudlReturn 正确创建父类方法,这样我就不必包含在我的所有观点中。

谢谢!

最佳答案

I am importing .m because it contains the textfieldshouldreturn method, it also imports the .h file



它正在导入导致重复符号的 .m 文件。导入 .m 文件会导致从中导入它的文件定义与包含的 .m 文件相同的符号(例如方法实现和具有外部范围的函数/变量),从而导致重复。

出于同样的原因,永远不要放置 @implementation block 到头文件中。

为了解决这个问题,为 GAViewController 创建一个标题。 , 并声明 textFieldShouldReturn:在里面。删除 #import "GAViewController.m"从您的标题和 .m 文件中替换为 #import "GAViewController.h" .这应该可以解决问题。

关于ios uiviewcontroller继承抛出重复符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24394435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com