我有PSCollectionView
我曾经使用过一次。
现在我想在另一个ViewController
中再次使用它,但是当我开始实现它时,我到处都会得到Duplicate interface definition for class 'PSCollectionView'
和Property has a previous declaration
。我不知道该怎么做。
像这样:
self.waterflowView = [[PSCollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.waterflowView.delegate = self; // This is for UIScrollViewDelegate
self.waterflowView.collectionViewDelegate = self;
self.waterflowView.collectionViewDataSource = self;
self.waterflowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.waterflowView.delaysContentTouches = NO;
if ([[UIDevice currentDevice].model isEqualToString:@"iPhone"]) {
self.waterflowView.numColsPortrait = 1;
self.waterflowView.numColsLandscape = 2;
} else {
self.waterflowView.numColsPortrait = 1;
self.waterflowView.numColsLandscape = 2;
}
[self.mainView addSubview:waterflowView];
当我为第二个想要做的UIScrollView添加此代码时
@interface KerkoViewController : UIViewController <UIScrollViewDelegate, PSCollectionViewDataSource, PSCollectionViewDelegate>
我在这些行中的PSCollectionView.h文件中收到错误:
@interface PSCollectionView : UIScrollView
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, assign, readonly) CGFloat colWidth;
@property (nonatomic, assign, readonly) NSInteger numCols;
@property (nonatomic, assign) NSInteger numColsLandscape;
@property (nonatomic, assign) NSInteger numColsPortrait;
@property (nonatomic, unsafe_unretained) id <PSCollectionViewDelegate> collectionViewDelegate;
@property (nonatomic, unsafe_unretained) id <PSCollectionViewDataSource> collectionViewDataSource;
和导入语句
#import <UIKit/UIKit.h>
#import "QuartzCore/QuartzCore.h"#include <mach/mach.h>
#include <mach/mach_time.h>
#include "PSCollectionView.h"
#import "WaterflowViewCell.h"
#import "MWPhotoBrowser.h"
答案 0 :(得分:1)
您应该使用#import
指令而不是#include
指令,否则编译器会尝试再次包含头文件,这会导致您收到错误消息。
使用#import
,编译器将自行处理。