简体   繁体   English

多个ViewController继承导致Apple Mach-O链接器错误

[英]Multiple ViewController inheritance causes Apple Mach-O Linker Error

I'm setting up a base view controller called "BHAccountBaseViewController" and two other views that inherit from some basic functionality from the base controller. 我正在设置一个名为“ BHAccountBaseViewController”的基本视图控制器,以及另外两个从该基本控制器的一些基本功能继承的视图。

  1. "BHAccountBaseViewController" Inherits from "UIViewController" “ BHAccountBaseViewController”继承自“ UIViewController”
  2. "BHAccountViewController" (implements UITextFieldDelegate) and Inherits from "BHAccountBaseViewController" “ BHAccountViewController”(实现UITextFieldDelegate)并从“ BHAccountBaseViewController”继承
  3. Lastly I have one recently created class that I called "BHCreateProfileViewController" every time that I just simply include #import directive to "BHAccountBaseViewController" to inherit from this class Xcode fails to compile due to APPLE MACH-O LINKER ERROR! 最后,我有一个最近创建的类,每当我只是简单地将#import指令包括在“ BHAccountBaseViewController”中以从该类继承时,我就将其称为“ BHCreateProfileViewController”。由于APPLE MACH-O LINKER错误,Xcode无法编译!

clang: error: linker command failed with exit code 1 (use -v to see invocation) clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

Thoughts? 思考? these are my three header files 这是我的三个头文件

BHAccountBaseViewController BHAccountBaseViewController

#import <UIKit/UIKit.h>
#import "BHFileManager.h"

@interface BHAccountBaseViewController : UIViewController
@end

BHAccountViewController BHAccountViewController

#import "BHAccountBaseViewController.h"
@interface BHAccountViewController : BHAccountBaseViewController<UITextFieldDelegate>
@end

BHCreateProfileViewController BHCreateProfileViewController

#import "BHAccountBaseViewController.m"
@interface BHCreateProfileViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) id user;
@end

if I comment out the import on the last file the linker error goes a way! 如果我在最后一个文件上注释了导入,则链接器错误会出路! but I want to be able to inherit from my base clase ... thoughts? 但我希望能够从我的基本经历中继承...的想法?

Help would be much appreciated! 帮助将不胜感激!

In implementation of BHCreateProfileViewController given above, I found the code looks like getting wrong at first line. 在上面给出的BHCreateProfileViewController的实现中,我发现代码看起来像在第一行就出错了。 What about fixing it as following: 如何修复它,如下所示:

#import "BHAccountBaseViewController.m"

to

#import "BHAccountBaseViewController.h"

and I wonder why BHCreateProfileViewController comes to inherit from UIViewController not BHAccountBaseViewController. 我不知道为什么BHCreateProfileViewController继承自UIViewController而不是BHAccountBaseViewController。 Could you explain that? 你能解释一下吗?

This might be due to the retain cycle deadlock problem. 这可能是由于保留周期死锁问题。 You have to use forward class declaration for this ie you can try @Class instead of #import. 您必须为此使用正向类声明,即可以尝试使用@Class而不是#import。 Please refer to these limks : 请参考以下说明:

Objective-C: Forward Class Declaration 目标C:前瞻性声明

@class vs. #import @class与#import

These might help. 这些可能会有所帮助。

In the compilation time your compiler would actually look for your interface files instead of implementation file.Compiler does not bother even if .m file is not available. 在编译期间,编译器实际上会查找您的接口文件而不是实现文件。即使.m文件不可用,编译器也不会打扰。 So while importing you are supposed to import .h instead .m. 因此,在导入时应该导入.h而不是.m。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM