我可以使用两次自定义UIScrollView吗?

时间:2014-07-30 13:38:14

标签: ios uiscrollview

我有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"

1 个答案:

答案 0 :(得分:1)

您应该使用#import指令而不是#include指令,否则编译器会尝试再次包含头文件,这会导致您收到错误消息。

使用#import,编译器将自行处理。