Skip to content

Commit 7fd25a3

Browse files
committed
Use UICollectionViewCell
1 parent 4bc1836 commit 7fd25a3

8 files changed

+19
-24
lines changed

FSPageViewExample-Swift/FSPagerViewExample/BasicExampleViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable
163163
return self.numberOfItems
164164
}
165165

166-
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewBaseCell {
166+
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell {
167167
let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell
168168
cell.imageView?.image = UIImage(named: self.imageNames[index])
169169
cell.imageView?.contentMode = .scaleAspectFill

FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class PageControlExampleViewController: UIViewController,UITableViewDataSource,U
215215
return self.imageNames.count
216216
}
217217

218-
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewBaseCell {
218+
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell {
219219
let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell
220220
cell.imageView?.image = UIImage(named: self.imageNames[index])
221221
cell.imageView?.contentMode = .scaleAspectFill

FSPageViewExample-Swift/FSPagerViewExample/TransformerExampleViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TransformerExampleViewController: UIViewController,FSPagerViewDataSource,F
9999
return imageNames.count
100100
}
101101

102-
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewBaseCell {
102+
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell {
103103
let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell
104104
cell.imageView?.image = UIImage(named: self.imageNames[index])
105105
cell.imageView?.contentMode = .scaleAspectFill

FSPagerViewExample-Objc/FSPagerViewExample-Objc/BasicExampleViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView
208208
return self.numberOfItems;
209209
}
210210

211-
- (FSPagerViewBaseCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
211+
- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
212212
{
213213
FSPagerViewCell *cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index];
214214
cell.imageView.image = [UIImage imageNamed:self.imageNames[index]];

FSPagerViewExample-Objc/FSPagerViewExample-Objc/PageControlExampleViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView
150150
return self.imageNames.count;
151151
}
152152

153-
- (FSPagerViewBaseCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
153+
- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
154154
{
155155
FSPagerViewCell *cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index];
156156
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;

FSPagerViewExample-Objc/FSPagerViewExample-Objc/TransformerExampleViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView
8080
return self.imageNames.count;
8181
}
8282

83-
- (FSPagerViewBaseCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
83+
- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index
8484
{
8585
FSPagerViewCell * cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index];
8686
cell.imageView.image = [UIImage imageNamed:self.imageNames[index]];

Sources/FSPagerView.swift

+12-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol FSPagerViewDataSource: NSObjectProtocol {
2121

2222
/// Asks your data source object for the cell that corresponds to the specified item in the pager view.
2323
@objc(pagerView:cellForItemAtIndex:)
24-
func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewBaseCell
24+
func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell
2525

2626
}
2727

@@ -46,11 +46,11 @@ public protocol FSPagerViewDelegate: NSObjectProtocol {
4646

4747
/// Tells the delegate that the specified cell is about to be displayed in the pager view.
4848
@objc(pagerView:willDisplayCell:forItemAtIndex:)
49-
optional func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewBaseCell, forItemAt index: Int)
49+
optional func pagerView(_ pagerView: FSPagerView, willDisplay cell: UICollectionViewCell, forItemAt index: Int)
5050

5151
/// Tells the delegate that the specified cell was removed from the pager view.
5252
@objc(pagerView:didEndDisplayingCell:forItemAtIndex:)
53-
optional func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewBaseCell, forItemAt index: Int)
53+
optional func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: UICollectionViewCell, forItemAt index: Int)
5454

5555
/// Tells the delegate when the pager view is about to start scrolling the content.
5656
@objc(pagerViewWillBeginDragging:)
@@ -379,15 +379,15 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
379379
return
380380
}
381381
let index = indexPath.item % self.numberOfItems
382-
function(self,cell as! FSPagerViewBaseCell,index)
382+
function(self,cell,index)
383383
}
384384

385385
public func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
386386
guard let function = self.delegate?.pagerView(_:didEndDisplaying:forItemAt:) else {
387387
return
388388
}
389389
let index = indexPath.item % self.numberOfItems
390-
function(self,cell as! FSPagerViewBaseCell,index)
390+
function(self,cell,index)
391391
}
392392

393393
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
@@ -451,7 +451,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
451451
/// Register a nib file for use in creating new pager view cells.
452452
///
453453
/// - Parameters:
454-
/// - nib: The nib object containing the cell object. The nib file must contain only one top-level object and that object must be of the type FSPagerViewBaseCell.
454+
/// - nib: The nib object containing the cell object. The nib file must contain only one top-level object and that object must be of the type UICollectionViewCell.
455455
/// - identifier: The reuse identifier to associate with the specified nib file. This parameter must not be nil and must not be an empty string.
456456
@objc(registerNib:forCellWithReuseIdentifier:)
457457
open func register(_ nib: UINib?, forCellWithReuseIdentifier identifier: String) {
@@ -463,15 +463,12 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
463463
/// - Parameters:
464464
/// - identifier: The reuse identifier for the specified cell. This parameter must not be nil.
465465
/// - index: The index specifying the location of the cell.
466-
/// - Returns: A valid FSPagerViewBaseCell object.
466+
/// - Returns: A valid UICollectionViewCell object.
467467
@objc(dequeueReusableCellWithReuseIdentifier:atIndex:)
468-
open func dequeueReusableCell(withReuseIdentifier identifier: String, at index: Int) -> FSPagerViewBaseCell {
468+
open func dequeueReusableCell(withReuseIdentifier identifier: String, at index: Int) -> UICollectionViewCell {
469469
let indexPath = IndexPath(item: index, section: self.dequeingSection)
470470
let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath)
471-
guard cell.isKind(of: FSPagerViewBaseCell.self) else {
472-
fatalError("Cell class must be subclass of FSPagerViewBaseCell")
473-
}
474-
return cell as! FSPagerViewBaseCell
471+
return cell
475472
}
476473

477474
/// Reloads all of the data for the collection view.
@@ -532,7 +529,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
532529
/// - Parameter cell: The cell object whose index you want.
533530
/// - Returns: The index of the cell or NSNotFound if the specified cell is not in the pager view.
534531
@objc(indexForCell:)
535-
open func index(for cell: FSPagerViewBaseCell) -> Int {
532+
open func index(for cell: UICollectionViewCell) -> Int {
536533
guard let indexPath = self.collectionView.indexPath(for: cell) else {
537534
return NSNotFound
538535
}
@@ -544,9 +541,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
544541
/// - Parameter index: The index that specifies the position of the cell.
545542
/// - Returns: The cell object at the corresponding position or nil if the cell is not visible or index is out of range.
546543
@objc(cellForItemAtIndex:)
547-
open func cellForItem(at index: Int) -> FSPagerViewBaseCell? {
544+
open func cellForItem(at index: Int) -> UICollectionViewCell? {
548545
let indexPath = self.nearbyIndexPath(for: index)
549-
return self.collectionView.cellForItem(at: indexPath) as? FSPagerViewBaseCell
546+
return self.collectionView.cellForItem(at: indexPath)
550547
}
551548

552549
// MARK: - Private functions

Sources/FSPagerViewCell.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
import UIKit
1010

11-
open class FSPagerViewBaseCell: UICollectionViewCell {}
12-
13-
open class FSPagerViewCell: FSPagerViewBaseCell {
11+
open class FSPagerViewCell: UICollectionViewCell {
1412

1513
/// Returns the label used for the main textual content of the pager view cell.
1614
@objc

0 commit comments

Comments
 (0)