Circular import issues in Objective C & Cocoa Touch

后端 未结 2 1756
别跟我提以往
别跟我提以往 2020-12-10 17:22

I have a view controller in Cocoa Touch that detects when the device rotates and switches between the views of the 2 view controllers it has: landscape and portrait.

相关标签:
2条回答
  • 2020-12-10 17:38

    If I'm reading it right your inheritance structure is like so:

    UIViewController-->FRRViewController-->FRRRotatingViewController

    But you have made the declaration of FRRViewController dependent on importing the file from its subclass, FRRRotatingViewController. The compiler will therefore be importing and reading FRRRotatingViewController before it processes the rest of FRRViewController.h.

    I'm assuming you've missed out some of FRRViewController.h since there is no reference to any rotating view controllers in there, but if you are declaring a property in .h of FRRRotatingViewController, then you need to use a forward declaration in FRRViewController.h:

    @class FRRRotatingViewController
    

    instead of

    #import "FRRRotatingViewController.h"
    

    The latter line, you can put in the first line of your FRRViewController.m file.

    0 讨论(0)
  • 2020-12-10 17:49

    You can use forward declarations for classes and protocols in headers in most situations to avoid circular import issues, except in the case of inheritance. In FRRViewController.h, instead of importing FRRRotatingViewController.h, can you not make a forward declaration?

    @class FRRRotatingViewController;
    
    0 讨论(0)
提交回复
热议问题