ios - 为什么导入 ViewController 会导致 Xcode 无法找到另一个 ViewController?

标签 ios objective-c iphone xcode uiviewcontroller

我的项目结构/依赖项是:

AppDelegate --> 导入“FirstRunViewController”和“MainViewController”

  • 如果用户已登录,它将 rootViewController 设置为 MainViewController
  • 如果用户未登录,则将 rootViewController 设置为 FirstRunViewController

FirstRunViewController --> 导入“MainViewController”

  • 登录/注册后,它将 viewController 设置为 MainViewController

MainViewController --> 导入“SettingsViewController”

  • 在需要时呈现 SettingsViewController

SettingsViewController --> 导入“FirstRunViewController”

  • 如果用户选择注销,它将viewController设置为FirstRunViewController

我的问题

在“SettingsViewController”中导入“FirstRunViewController”(处理注销)会导致 Xcode 无法在另一个不相关的 ViewController 中找到有效的委托(delegate)。具体错误码为“No type or protocol named ABCDelegate”。

删除“#import”语句将允许代码运行和编译,但会禁用注销。

我的问题

为什么会这样?

我怎样才能阻止这种情况发生?

最佳答案

我不确定。但是随着你的流程,我觉得这是由于循环依赖而发生的。

解决方案:-

使用 .pch 文件并将您的所有文件导入 .pch 文件并根据您的要求使用它。

关于 .pch 文件的详细讨论,请查看。

what-is-prefix-pch-file-in-xcode

关于ios - 为什么导入 ViewController 会导致 Xcode 无法找到另一个 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36381335/

相关文章:

objective-c - 无法使用stringWithContentsOfURL检索某些页面

iphone - Objective-C : call super class

ios - 隐藏导航 Controller 的 rightBarButtonItem

iphone - 使用跨度缩放到用户位置

ios - Swift 2.1 Core Data - 保存具有一对多关系的数据,但如果已经存在则不添加 isome 数据

ios - Xcode 5.1.1 - 错误 : Start Page at 'www/index.html' was not found

iOS swift : best way to pass data to other VCs after query is completed

ios - UIWebView HTML 5 游戏 Canvas 在 iOS 9 中绘制缓慢,或 WebGL 在 iOS 8.0 及更高版本中崩溃

ios - 在 .xib 中使用自定义 UIView 作为 IBOutlet

iphone - 初始化 NSMutableArray 的内存/设计模式/重构