objective-c - Objective-C : Where to #import protocol header files

标签 objective-c ios import header protocols

在 iOS 应用程序中,我正在定义自己的协议(protocol)以在我的自定义 View Controller 中使用委托(delegate)模式。哪些文件应该 #import还有哪些文件?也就是说,我的案例涉及到四个文件:

  • MainViewController.h : 声明协议(protocol)和 View Controller 而不是实现协议(protocol)
  • MainViewController.m : 实现协议(protocol)方法
  • SecondaryViewController.h : 声明类型为id <Protocol> 的委托(delegate)实例变量和属性(前向声明 Protocol )
  • SecondaryViewController.m : 在委托(delegate)上使用协议(protocol)方法

哪些文件应该#import还有哪些?我认为第二个 View Controller 的 header 中的前向声明就足够了,但除非第二个 header 或实现导入主 header ,否则我会收到编译警告/错误。

最佳答案

SecondaryViewController.m 应该 #import 'MainViewController.h

关于objective-c - Objective-C : Where to #import protocol header files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6062353/

相关文章:

ios - TabBarViewController 的导航栏覆盖了导航 Controller 中的导航栏

ios - UITableView 中的复选框

azure - Import-AzKeyVaultCertificate cmdlet 结果为 : Key not valid for user in specified state

python - Pygame菜单: calling another . py文件

ios - 为纵向和横向模式获得相同的屏幕宽度和高度

ios - 调整导航栏中 UISearchBar 的大小?

objective-c - AVFoundation 以自定义分辨率捕获视频

ios - MKStoreKit 的通知

java - 从 Informix 批量导入到 Oracle

ios - 当使用相同坐标绘制的图像形成圆弧时,CGRect 中绘制的文本标签形成椭圆弧