diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6745b157 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Pods/Pods.xcodeproj/xcuserdata/zhangzhenghong.xcuserdatad/xcschemes/xcschememanagement.plist +SDCycleScrollView.xcodeproj/xcuserdata/zhangzhenghong.xcuserdatad/xcschemes/xcschememanagement.plist +SDCycleScrollView.xcworkspace/xcuserdata/zhangzhenghong.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h index e6a290eb..3ba05020 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h @@ -67,8 +67,12 @@ typedef enum { // ========== 轮播自定义cell ========== -/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */ -- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view; +/** + * 如果你需要自定义cell样式,请在实现此代理方法 + * 返回自定义cell的class。 + * 如使用Xib创建cell,返回UINib + */ +- (id)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view; /** 如果你自定义了cell样式,请在实现此代理方法为你的cell填充数据以及其它一系列设置 */ - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view; diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m index d0b3fc8d..ac4f0914 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m @@ -157,8 +157,15 @@ - (void)setDelegate:(id)delegate { _delegate = delegate; - if ([self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) { - [self.mainView registerClass:[self.delegate customCollectionViewCellClassForCycleScrollView:self] forCellWithReuseIdentifier:ID]; + if ([self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)]) { + id class = [self.delegate customCollectionViewCellClassForCycleScrollView:self]; + if (!class) {return;} + if ([class isKindOfClass:[UINib class]]) { + UINib *nib = class; + [self.mainView registerNib:nib forCellWithReuseIdentifier:ID]; + } else { + [self.mainView registerClass:class forCellWithReuseIdentifier:ID]; + } } } @@ -566,17 +573,20 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - SDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; + long itemIndex = [self pageControlIndexWithCurrentCellIndex:indexPath.item]; if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] && [self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) { + UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; [self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self]; return cell; } + SDCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; + NSString *imagePath = self.imagePathsGroup[itemIndex]; if (!self.onlyDisplayText && [imagePath isKindOfClass:[NSString class]]) {