SMGridView Class Reference
| Inherits from | UIScrollView |
| Conforms to | UIScrollViewDelegate |
| Declared in | SMGridView.h |
Overview
This open-source class allows you to have a custom grid that will use methods similar to UITableView (and UITableViewDataSource and UITableViewDelegate) and that supports a lot of extra functionality like:
- Choose between horizontal or vertical scroll.
- Support for any view, not just a fixed view like UITableViewCell.
- Support for sections.
- Support for inserting or deleting items with an animation.
- Support to sort items using drag & drop.
- Veeeery fast, supporting reusing views.
- It is a UIScrollView, so you can access all its methods and set its UIScrollViewDelegate.
- Supports pagination.
- You can use this class even if you don’t plan to scroll, just to layout items in a grid or line (single row grid).
- Ability to display a loader at the end of the grid
Tasks
-
dataSourceproperty -
gridDelegateproperty -
numberOfRowsYou can use this property to set the numberOfRows if all your sections have the same number. Otherwise use [SMGridViewDataSource smGridView:numberOfRowsInSection:]
property -
paddingThis is the space between every view in the grid
property -
deltaLoadIn logical pixels, how much more of the size of the grid is being preloaded.
property -
deltaLoaderViewIn logical pixels, use this property to make possible to preload the loaderView before it appears in the screen
property -
pagesToPreloadHow many extra pages to you want to preload if paging is enabled
property -
verticalSet this to
propertyYESto have vertical scrolling -
pagingInverseOrderSet this property to
propertyYESwhen paging is enabled to change the order of the items -
currentPageIf pagingEnabled is
propertyYES, returns the current Page in the grid -
loaderViewUse this property to have a custom loaderView at the end of the grid Use in combination with [SMGridViewDataSource smGridViewShowLoader:]
property -
emptyViewThis view will be displayed when dataSource has no items
property -
numberOfPagesIf pagingEnabled is
propertyYES, return the total number of pages in the grid -
enableSortUse this property to have a custom loaderView at the end of the grid Use in combination with [SMGridViewDataSource smGridView:shouldMoveItemFrom:to:]
property -
dragMinDistanceIn logical pixels, how far a dragged view needs to be from another view to be able to swap its position.
property -
draggingPointThis can be used to change the draggingPoint when sorting is enabled This is useful if you change the size of the view you are sorting.
property -
busyReturns wether or not the grid is sorting or animating (adding/removing)
property -
stickyHeadersDecides wether headers should be sticky or not
property -
currentSectionReturns the section being shown right now
property -
hasItemsWether a grid has or not items
property -
sortWaitBeforeAnimateDetermines time to wait after the user stops moving a view before the sort animation starts (To be deprecated)
property -
– reloadDataCall this method once your dataSource is ready to create the views inside the grid
-
– reloadSection:Like method reloadData but only for a specific section
-
– reloadDataWithPage:Calls method reloadData and positions itself in the given page
-
– reloadDataOnlyNewLike method reloadSectionOnlyNew: with section being the last section.
-
– reloadSectionOnlyNew:Use this method when you know the dataSource only added new items (and didn’t change the ones before) to the given section.
-
– dequeReusableViewCall this method to get a reusable view
-
– dequeReusableViewOfClass:Call this method to get a reusable view of a specific class
-
– clearReusableViewsCall this method to remove the reusable views
-
– addItemAtIndexPath:Like method addItemAtIndexPath:scroll: with scroll to
YES -
– addItemAtIndexPath:scroll:You should call this method once the dataSource has already addded the item
-
– removeItemAtIndexPath:Like method removeItemAtIndexPath:scroll: with scroll to
YES -
– removeItemAtIndexPath:scroll:You should call this method before the property dataSource has removed the item. Once the item is removed (after the animation), the dataSource will receive a call to smGridView:performRemoveIndexPath: to finally remove the item
-
– indexPathForView:The view whose indexPath you are interested
-
– viewForIndexPath:The target indexPath
-
– resetScroll:Sets the contentOffset to 0
-
– setCurrentPage:animated:Change the current page if paging is enabled
-
– currentViewsSame as method currentViews: with includeHeaders to
NO -
– currentViews:All visible views
-
– headerViewForSection:eturns headerView for section if the view is being shown. Headers are not supported if
pagingEnabledisYES -
– contentOffsetForPage:The contentOffset for a page if pagingEnabled is
YES -
– touchDown:withLocationInView:Use this method to simulate a touchDown event to start dragging
Properties
busy
Returns wether or not the grid is sorting or animating (adding/removing)
@property (nonatomic, readonly) BOOL busyDeclared In
SMGridView.hcurrentPage
If pagingEnabled is YES, returns the current Page in the grid
@property (nonatomic, assign) NSInteger currentPageDeclared In
SMGridView.hcurrentSection
Returns the section being shown right now
@property (nonatomic, readonly) NSInteger currentSectionDeclared In
SMGridView.hdataSource
@property (nonatomic, assign) id<SMGridViewDataSource> dataSourceDeclared In
SMGridView.hdeltaLoad
In logical pixels, how much more of the size of the grid is being preloaded.
@property (nonatomic, assign) CGFloat deltaLoadDeclared In
SMGridView.hdeltaLoaderView
In logical pixels, use this property to make possible to preload the loaderView before it appears in the screen
@property (nonatomic, assign) CGFloat deltaLoaderViewDeclared In
SMGridView.hdragMinDistance
In logical pixels, how far a dragged view needs to be from another view to be able to swap its position.
@property (nonatomic, assign) float dragMinDistanceDeclared In
SMGridView.hdraggingPoint
This can be used to change the draggingPoint when sorting is enabled This is useful if you change the size of the view you are sorting.
@property (nonatomic, assign) CGPoint draggingPointDeclared In
SMGridView.hemptyView
This view will be displayed when dataSource has no items
@property (nonatomic, retain) UIView *emptyViewDeclared In
SMGridView.henableSort
Use this property to have a custom loaderView at the end of the grid Use in combination with [SMGridViewDataSource smGridView:shouldMoveItemFrom:to:]
@property (nonatomic, assign) BOOL enableSortDeclared In
SMGridView.hgridDelegate
@property (nonatomic, assign) id<SMGridViewDelegate> gridDelegateDeclared In
SMGridView.hhasItems
Wether a grid has or not items
@property (nonatomic, readonly) BOOL hasItemsDeclared In
SMGridView.hloaderView
Use this property to have a custom loaderView at the end of the grid Use in combination with [SMGridViewDataSource smGridViewShowLoader:]
@property (nonatomic, retain) UIView *loaderViewDeclared In
SMGridView.hnumberOfPages
If pagingEnabled is YES, return the total number of pages in the grid
@property (nonatomic, readonly) NSInteger numberOfPagesDeclared In
SMGridView.hnumberOfRows
You can use this property to set the numberOfRows if all your sections have the same number. Otherwise use [SMGridViewDataSource smGridView:numberOfRowsInSection:]
@property (nonatomic, assign) NSInteger numberOfRowsDeclared In
SMGridView.hpadding
This is the space between every view in the grid
@property (nonatomic, assign) CGFloat paddingDeclared In
SMGridView.hpagesToPreload
How many extra pages to you want to preload if paging is enabled
@property (nonatomic, assign) NSInteger pagesToPreloadDeclared In
SMGridView.hpagingInverseOrder
Set this property to YES when paging is enabled to change the order of the items
@property (nonatomic, assign) BOOL pagingInverseOrderDeclared In
SMGridView.hsortWaitBeforeAnimate
Determines time to wait after the user stops moving a view before the sort animation starts (To be deprecated)
@property (nonatomic, assign) NSTimeInterval sortWaitBeforeAnimateDeclared In
SMGridView.hInstance Methods
addItemAtIndexPath:
Like method addItemAtIndexPath:scroll: with scroll to YES
- (void)addItemAtIndexPath:(NSIndexPath *)indexPathParameters
- indexPath
IndexPath of item to add
Declared In
SMGridView.haddItemAtIndexPath:scroll:
You should call this method once the dataSource has already addded the item
- (void)addItemAtIndexPath:(NSIndexPath *)indexPath scroll:(BOOL)scrollParameters
- indexPath
The indexPath where the new item is in the property dataSource
- scroll
indicates wether the grid should scroll to show the animation or not
Declared In
SMGridView.hclearReusableViews
Call this method to remove the reusable views
- (void)clearReusableViewsDeclared In
SMGridView.hcontentOffsetForPage:
The contentOffset for a page if pagingEnabled is YES
- (CGPoint)contentOffsetForPage:(NSInteger)pageParameters
- page
Page number
Return Value
The contentOffset for a page if pagingEnabled is YES
Declared In
SMGridView.hcurrentViews
Same as method currentViews: with includeHeaders to NO
- (NSArray *)currentViewsDeclared In
SMGridView.hcurrentViews:
All visible views
- (NSArray *)currentViews:(BOOL)includeHeadersParameters
- includeHeaders
Set to
YESto also get header views back
Return Value
All visible views
Declared In
SMGridView.hdequeReusableView
Call this method to get a reusable view
- (UIView *)dequeReusableViewReturn Value
An already used view or nils
Declared In
SMGridView.hdequeReusableViewOfClass:
Call this method to get a reusable view of a specific class
- (UIView *)dequeReusableViewOfClass:(Class)clazzParameters
- clazz
The class you want the returning object to be
Return Value
A view of the provided class or nil if not available
Declared In
SMGridView.hheaderViewForSection:
eturns headerView for section if the view is being shown. Headers are not supported if pagingEnabledis YES
- (UIView *)headerViewForSection:(NSInteger)sectionParameters
- section
Section number
Return Value
eturns headerView for section if the view is being shown. Headers are not supported if pagingEnabledis YES
Declared In
SMGridView.hindexPathForView:
The view whose indexPath you are interested
- (NSIndexPath *)indexPathForView:(UIView *)viewParameters
- view
The view whose indexPath you are interested
Return Value
The NSIndexPath associated with a view. nil if the view is not being shown
Declared In
SMGridView.hreloadData
Call this method once your dataSource is ready to create the views inside the grid
- (void)reloadDataDeclared In
SMGridView.hreloadDataOnlyNew
Like method reloadSectionOnlyNew: with section being the last section.
- (void)reloadDataOnlyNewDeclared In
SMGridView.hreloadDataWithPage:
Calls method reloadData and positions itself in the given page
- (void)reloadDataWithPage:(NSInteger)pageParameters
- page
Number of page to reload
Declared In
SMGridView.hreloadSection:
Like method reloadData but only for a specific section
- (void)reloadSection:(NSInteger)sectionParameters
- section
Index of section to reload
Declared In
SMGridView.hreloadSectionOnlyNew:
Use this method when you know the dataSource only added new items (and didn’t change the ones before) to the given section.
- (void)reloadSectionOnlyNew:(NSInteger)sectionParameters
- section
The index of the section to reload
Declared In
SMGridView.hremoveItemAtIndexPath:
Like method removeItemAtIndexPath:scroll: with scroll to YES
- (void)removeItemAtIndexPath:(NSIndexPath *)indexPathParameters
- indexPath
indexPath of item to remove
Declared In
SMGridView.hremoveItemAtIndexPath:scroll:
You should call this method before the property dataSource has removed the item. Once the item is removed (after the animation), the dataSource will receive a call to smGridView:performRemoveIndexPath: to finally remove the item
- (void)removeItemAtIndexPath:(NSIndexPath *)indexPath scroll:(BOOL)scrollParameters
- indexPath
The indexPath in the property dataSource you want to remove
- scroll
indicates wether the grid should scroll to show the animation or not
Declared In
SMGridView.hresetScroll:
Sets the contentOffset to 0
- (void)resetScroll:(BOOL)animatedParameters
- animated
Wether or not to animate the scroll
Declared In
SMGridView.hsetCurrentPage:animated:
Change the current page if paging is enabled
- (void)setCurrentPage:(NSInteger)page animated:(BOOL)animatedParameters
- page
The new page number
- animated
Wether or not to animate when moving to that page
Declared In
SMGridView.h