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

Properties

busy

Returns wether or not the grid is sorting or animating (adding/removing)

@property (nonatomic, readonly) BOOL busy

Declared In

SMGridView.h

currentPage

If pagingEnabled is YES, returns the current Page in the grid

@property (nonatomic, assign) NSInteger currentPage

Declared In

SMGridView.h

currentSection

Returns the section being shown right now

@property (nonatomic, readonly) NSInteger currentSection

Declared In

SMGridView.h

dataSource

@property (nonatomic, assign) id<SMGridViewDataSource> dataSource

Declared In

SMGridView.h

deltaLoad

In logical pixels, how much more of the size of the grid is being preloaded.

@property (nonatomic, assign) CGFloat deltaLoad

Declared In

SMGridView.h

deltaLoaderView

In logical pixels, use this property to make possible to preload the loaderView before it appears in the screen

@property (nonatomic, assign) CGFloat deltaLoaderView

Declared In

SMGridView.h

dragMinDistance

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 dragMinDistance

Declared In

SMGridView.h

draggingPoint

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 draggingPoint

Declared In

SMGridView.h

emptyView

This view will be displayed when dataSource has no items

@property (nonatomic, retain) UIView *emptyView

Declared In

SMGridView.h

enableSort

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 enableSort

Declared In

SMGridView.h

gridDelegate

@property (nonatomic, assign) id<SMGridViewDelegate> gridDelegate

Declared In

SMGridView.h

hasItems

Wether a grid has or not items

@property (nonatomic, readonly) BOOL hasItems

Declared In

SMGridView.h

loaderView

Use this property to have a custom loaderView at the end of the grid Use in combination with [SMGridViewDataSource smGridViewShowLoader:]

@property (nonatomic, retain) UIView *loaderView

Declared In

SMGridView.h

numberOfPages

If pagingEnabled is YES, return the total number of pages in the grid

@property (nonatomic, readonly) NSInteger numberOfPages

Declared In

SMGridView.h

numberOfRows

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 numberOfRows

Declared In

SMGridView.h

padding

This is the space between every view in the grid

@property (nonatomic, assign) CGFloat padding

Declared In

SMGridView.h

pagesToPreload

How many extra pages to you want to preload if paging is enabled

@property (nonatomic, assign) NSInteger pagesToPreload

Declared In

SMGridView.h

pagingInverseOrder

Set this property to YES when paging is enabled to change the order of the items

@property (nonatomic, assign) BOOL pagingInverseOrder

Declared In

SMGridView.h

sortWaitBeforeAnimate

Determines time to wait after the user stops moving a view before the sort animation starts (To be deprecated)

@property (nonatomic, assign) NSTimeInterval sortWaitBeforeAnimate

Declared In

SMGridView.h

stickyHeaders

Decides wether headers should be sticky or not

@property (nonatomic, assign) BOOL stickyHeaders

Declared In

SMGridView.h

vertical

Set this to YES to have vertical scrolling

@property (nonatomic, assign) BOOL vertical

Declared In

SMGridView.h

Instance Methods

addItemAtIndexPath:

Like method addItemAtIndexPath:scroll: with scroll to YES

- (void)addItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

IndexPath of item to add

Declared In

SMGridView.h

addItemAtIndexPath:scroll:

You should call this method once the dataSource has already addded the item

- (void)addItemAtIndexPath:(NSIndexPath *)indexPath scroll:(BOOL)scroll

Parameters

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.h

clearReusableViews

Call this method to remove the reusable views

- (void)clearReusableViews

Declared In

SMGridView.h

contentOffsetForPage:

The contentOffset for a page if pagingEnabled is YES

- (CGPoint)contentOffsetForPage:(NSInteger)page

Parameters

page

Page number

Return Value

The contentOffset for a page if pagingEnabled is YES

Declared In

SMGridView.h

currentViews

Same as method currentViews: with includeHeaders to NO

- (NSArray *)currentViews

Declared In

SMGridView.h

currentViews:

All visible views

- (NSArray *)currentViews:(BOOL)includeHeaders

Parameters

includeHeaders

Set to YES to also get header views back

Return Value

All visible views

Declared In

SMGridView.h

dequeReusableView

Call this method to get a reusable view

- (UIView *)dequeReusableView

Return Value

An already used view or nils

Declared In

SMGridView.h

dequeReusableViewOfClass:

Call this method to get a reusable view of a specific class

- (UIView *)dequeReusableViewOfClass:(Class)clazz

Parameters

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.h

headerViewForSection:

eturns headerView for section if the view is being shown. Headers are not supported if pagingEnabledis YES

- (UIView *)headerViewForSection:(NSInteger)section

Parameters

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.h

indexPathForView:

The view whose indexPath you are interested

- (NSIndexPath *)indexPathForView:(UIView *)view

Parameters

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.h

reloadData

Call this method once your dataSource is ready to create the views inside the grid

- (void)reloadData

Declared In

SMGridView.h

reloadDataOnlyNew

Like method reloadSectionOnlyNew: with section being the last section.

- (void)reloadDataOnlyNew

Declared In

SMGridView.h

reloadDataWithPage:

Calls method reloadData and positions itself in the given page

- (void)reloadDataWithPage:(NSInteger)page

Parameters

page

Number of page to reload

Declared In

SMGridView.h

reloadSection:

Like method reloadData but only for a specific section

- (void)reloadSection:(NSInteger)section

Parameters

section

Index of section to reload

Declared In

SMGridView.h

reloadSectionOnlyNew:

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)section

Parameters

section

The index of the section to reload

Declared In

SMGridView.h

removeItemAtIndexPath:

Like method removeItemAtIndexPath:scroll: with scroll to YES

- (void)removeItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

indexPath of item to remove

Declared In

SMGridView.h

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

- (void)removeItemAtIndexPath:(NSIndexPath *)indexPath scroll:(BOOL)scroll

Parameters

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.h

resetScroll:

Sets the contentOffset to 0

- (void)resetScroll:(BOOL)animated

Parameters

animated

Wether or not to animate the scroll

Declared In

SMGridView.h

setCurrentPage:animated:

Change the current page if paging is enabled

- (void)setCurrentPage:(NSInteger)page animated:(BOOL)animated

Parameters

page

The new page number

animated

Wether or not to animate when moving to that page

Declared In

SMGridView.h

touchDown:withLocationInView:

Use this method to simulate a touchDown event to start dragging

- (void)touchDown:(UIControl *)controlView withLocationInView:(CGPoint)point

Parameters

controlView

The view touched

point

Location inside controlView

Declared In

SMGridView.h

viewForIndexPath:

The target indexPath

- (UIView *)viewForIndexPath:(NSIndexPath *)indexPath

Parameters

indexPath

The target indexPath

Return Value

The view associated with an indexPath if it is being shown. Return nil if it is not being shown.

Declared In

SMGridView.h