简体   繁体   English

如何避免导入类并实现协议?

[英]How to avoid import class and implement protocol?

One ViewController class already imported the UIView class into it. 一个ViewController类已经将UIView类导入了其中。 Now when implementing the protocol into same class. 现在,当将协议实现为同一类时。

Here @protocol class in already imported WeeklyView Class. 这里@protocol类已经导入了WeeklyView类中。

Now in Weekly View I got scenario to implement the @protocol method. 现在在Weekly View中,我实现了实现@protocol方法的方案。 So i need import PlanViewController into there. 所以我需要导入PlanViewController到那里。

It looks like classA import ClassB and ClassB import ClassA that is wrong. 看起来classA导入ClassB和ClassB导入ClassA是错误的。

How to avoid this behaviour in this case? 在这种情况下如何避免这种行为? and implement the protocol. 并实施该协议。

// ViewController class // ViewController类

#import <UIKit/UIKit.h>
#import "WeeklyView.h"
@protocol PlanViewControllerDelegate <NSObject>
@optional
-(void)nextWeekGlanceCategory :(NSString *)startweekDate endWeekDate:(NSString *)endWeekDate;
@end

// Another class Weeklyview //另一个类Weeklyview

#import <UIKit/UIKit.h>
#import "PlanViewController.h"
@interface WeeklyView : UIView <UITableViewDelegate,UITableViewDataSource,PlanViewControllerDelegate>

Just put your protocol in separate header file. 只需将协议放在单独的头文件中即可。

To create protocol header file you can pick it like this: File->New->Objective-c File->Protocol. 要创建协议头文件,您可以像这样选择它:File-> New-> Objective-c File-> Protocol。

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

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