UIViewController calling each other's delegate

后端 未结 3 1275
臣服心动
臣服心动 2021-01-14 19:47

I have two UIViewController, each has it\'s delegate and is calling one or the other. One class is called TopicViewController and the other is MentionViewController, the cod

3条回答
  •  花落未央
    2021-01-14 20:07

    It is really strange. The MentionViewController needs the header file of DetailViewController, and the DetailViewController needs MentionViewController's header file. It is a cycle. Maybe you need to create a empty header file, and put all protocol inside it. For example,

    MyProtocol.h

    @class DetailViewController;
    @class MentionViewController;
    
    @protocol DetailViewControllerDelegate
    
    - (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;
    
    @end
    
    @protocol MentionViewControllerDelegate
    
    - (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;
    
    @end
    

    And add #import MyProtocol.h inside DetailViewController.h and MentionViewController.h.

提交回复
热议问题