UISwipesViewDataSource Protocol Reference

Declared in UISwipesView.h

Overview

UISwipesViewDataSource is a common protocol for data containment, made specifically for UISwipesView. The UISwipesViewDataSource works just like any other UIKit dataSource, and the following is a basic implementation of UISwipesViewDataSource:

@interface BasicSwipes () <UISwipesViewDataSource>
@property (strong, nonatomic) NSMutableArray *cardData;
@property (strong, nonatomic) CGRect screenBounds;
@end

@implementation BasicSwipes

 - (void)viewDidLoad {
     [super viewDidLoad];

     self.screenBounds = [[UIScreen mainScreen] bounds];
     self.cardData = [[NSMutableArray alloc] initWithArray:@[ @1, @11, @111 ]];

     UISwipesView *swipesView = [[UISwipesView alloc] initWithFrame:self.screenBounds];
     [self.view addSubview:swipesView];
     [swipesView setDataSource:self];

     [swipesView registerClass:[BasicCardCell class] forCellWithReuseIdentifier:@"BasicCardCell"];

 }
 - (NSInteger)swipesView:(UISwipesView *)swipesView numberOfItemsInSection:(NSInteger) nis {
    return self.cardData.count;
 }

 - (CGPoint)swipesView:(UISwipesView *)swipesView centerForItemAtIndexPath:(NSIndexPath *)indexPath {
     return CGPointMake(self.screenBounds.width * .50f, self.screenBounds.height * .35f);
 }

 - (CGSize)swipesView:(UISwipesView *)swipesView sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
     CGFloat defaultCellSize = self.screenBounds.size.width;
     return CGSizeMake(defaultCellSize * .85f, defaultCellSize * .55f);
 }

 - (void)swipesView:(UISwipesView *)swipesView postSwipeOperationAtIndexPath:(NSIndexPath*)indexPath {
     [self.cardData removeObjectAtIndex:indexPath.item];
 }

 - (UISwipesViewCell *)swipesView:(UISwipesView *)swipesView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
     BasicCardCell *cell = (BasicCardCell*)[swipesView dequeueReusableCellWithReuseIdentifier:@"BasicCardCell" forIndexPath:indexPath];
     cell.label.text = [NSString stringWithFormat:@"%@", self.cardData[indexPath.item]];

     return cell;
 }
 @end

– swipesView:numberOfSectionsInSwipesView:

- (int)swipesView:(UISwipesView *)swipesView numberOfSectionsInSwipesView:(UISwipesView *)swipesView

– swipesView:centerForItemAtIndexPath: required method

Sets up and returns the center position in the UISwipesView.

- (CGPoint)swipesView:(UISwipesView *)swipesView centerForItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

swipesView

The Swipes View that can be used as a position reference.

indexPath

The position in the Swipes View of the UISwipesViewCell

Return Value

The CGPoint in the Swipes View of the UISwipesViewCell

Declared In

UISwipesView.h

– swipesView:sizeForItemAtIndexPath: required method

Sets up and returns the size in the UISwipesView.

- (CGSize)swipesView:(UISwipesView *)swipesView sizeForItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

swipesView

The Swipes View that can be used as a position reference.

indexPath

The position in the Swipes View of the UISwipesViewCell

Return Value

The CGSize within the Swipes View of the UISwipesViewCell

Declared In

UISwipesView.h

– swipesView:numberOfItemsInSection: required method

Sets up and returns the count in the UISwipesView within a section.

- (int)swipesView:(UISwipesView *)swipesView numberOfItemsInSection:(NSInteger)section

Parameters

swipesView

The Swipes View that can be used as a position reference.

indexPath

The position in the Swipes View of the UISwipesViewCell

Return Value

The count of items in the Swipes View Section

Declared In

UISwipesView.h

– swipesView:cellForItemAtIndexPath: required method

Sets up and returns a UISwipesViewCell in the UISwipesView.

- (UISwipesViewCell *)swipesView:(UISwipesView *)swipesView cellForItemAtIndexPath:(NSIndexPath *)indexPath

Parameters

swipesView

The Swipes View that can be used as a position reference.

indexPath

The position in the Swipes View of the UISwipesViewCell

Return Value

The cell data populated in the Swipes View Cell

Declared In

UISwipesView.h

– swipesView:postSwipeOperationAtIndexPath: required method

Is called after a Swipe Operation, and allows clean up of your data (deletions, moves, etc.).

- (void)swipesView:(UISwipesView *)swipesView postSwipeOperationAtIndexPath:(NSIndexPath *)indexPath

Parameters

swipesView

The Swipes View that can be used as a position reference.

indexPath

The position in the Swipes View of the UISwipesViewCell

Declared In

UISwipesView.h