Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use custom cell with Xib unused registeredNibPool method #420

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ - (void)setDelegate:(id<SDCycleScrollViewDelegate>)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];
}
}
}

Expand Down Expand Up @@ -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]]) {
Expand Down