forked from MortimerGoro/MGSwipeTableCell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b930d4
commit 52dc380
Showing
19 changed files
with
991 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
demo/MGSwipeDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* MGSwipeTableCell is licensed under MIT licensed. See LICENSE.md file for more information. | ||
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* MGSwipeTableCell is licensed under MIT licensed. See LICENSE.md file for more information. | ||
* Copyright (c) 2014 Imanol Fernandez @MortimerGoro | ||
*/ | ||
|
||
#import "AppDelegate.h" | ||
#import "DemoViewController.h" | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
|
||
DemoViewController * vc = [[DemoViewController alloc] initWithStyle:UITableViewStylePlain]; | ||
UINavigationController * navigation = [[UINavigationController alloc] initWithRootViewController:vc]; | ||
self.window.rootViewController = navigation; | ||
|
||
self.window.backgroundColor = [UIColor whiteColor]; | ||
[self.window makeKeyAndVisible]; | ||
return YES; | ||
} | ||
|
||
- (void)applicationWillResignActive:(UIApplication *)application | ||
{ | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
} | ||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application | ||
{ | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application | ||
{ | ||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application | ||
{ | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
|
||
- (void)applicationWillTerminate:(UIApplication *)application | ||
{ | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// DemoViewController.h | ||
// MGSwipeDemo | ||
// | ||
// Created by Imanol Fernandez Gorostizag on 09/08/14. | ||
// Copyright (c) 2014 Imanol Fernandez Gorostizaga. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "MGSwipeTableCell.h" | ||
|
||
@interface DemoViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate, MGSwipeTableCellDelegate, UIActionSheetDelegate> | ||
|
||
@property (nonatomic, assign) BOOL testingStoryboardCell; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
// | ||
// DemoViewController.m | ||
// MGSwipeDemo | ||
// | ||
// Created by Imanol Fernandez Gorostizag on 09/08/14. | ||
// Copyright (c) 2014 Imanol Fernandez Gorostizaga. All rights reserved. | ||
// | ||
|
||
#import "DemoViewController.h" | ||
#import "TestData.h" | ||
#import "MGSwipeButton.h" | ||
|
||
#define TEST_USE_MG_DELEGATE 1 | ||
|
||
@implementation DemoViewController | ||
{ | ||
NSMutableArray * tests; | ||
UIBarButtonItem * prevButton; | ||
} | ||
|
||
|
||
-(void) cancelTableEditClick: (id) sender | ||
{ | ||
[self.tableView setEditing: NO animated: YES]; | ||
self.navigationItem.rightBarButtonItem = prevButton; | ||
prevButton = nil; | ||
} | ||
|
||
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex | ||
{ | ||
if (buttonIndex == actionSheet.cancelButtonIndex) { | ||
return; | ||
} | ||
|
||
if (buttonIndex == 1) { | ||
tests = [TestData data]; | ||
[self.tableView reloadData]; | ||
} | ||
else if (buttonIndex == 2) { | ||
self.tableView.allowsMultipleSelectionDuringEditing = YES; | ||
[self.tableView setEditing: YES animated: YES]; | ||
prevButton = self.navigationItem.rightBarButtonItem; | ||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancelTableEditClick:)]; | ||
} | ||
else { | ||
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"autolayout_test" bundle:nil]; | ||
DemoViewController *vc = [sb instantiateInitialViewController]; | ||
vc.testingStoryboardCell = YES; | ||
[self.navigationController pushViewController:vc animated:YES]; | ||
} | ||
} | ||
|
||
-(void) actionClick: (id) sender | ||
{ | ||
|
||
UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"Select action" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: nil]; | ||
[sheet addButtonWithTitle:@"Reload test"]; | ||
[sheet addButtonWithTitle:@"Multiselect test"]; | ||
if (!_testingStoryboardCell) { | ||
[sheet addButtonWithTitle:@"Storyboard test"]; | ||
} | ||
[sheet showInView:self.view]; | ||
} | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
tests = [TestData data]; | ||
self.title = @"MGSwipeCell"; | ||
|
||
self.tableView.dataSource = self; | ||
self.tableView.delegate = self; | ||
|
||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionClick:)]; | ||
} | ||
|
||
|
||
-(NSArray *) createLeftButtons: (int) number | ||
{ | ||
NSMutableArray * result = [NSMutableArray array]; | ||
UIColor * colors[3] = {[UIColor greenColor], | ||
[UIColor colorWithRed:0 green:0x99/255.0 blue:0xcc/255.0 alpha:1.0], | ||
[UIColor colorWithRed:0.59 green:0.29 blue:0.08 alpha:1.0]}; | ||
UIImage * icons[3] = {[UIImage imageNamed:@"check.png"], [UIImage imageNamed:@"fav.png"], [UIImage imageNamed:@"menu.png"]}; | ||
for (int i = 0; i < number; ++i) | ||
{ | ||
MGSwipeButton * button = [MGSwipeButton buttonWithTitle:@"" icon:icons[i] backgroundColor:colors[i] callback:^BOOL(MGSwipeTableCell * sender){ | ||
NSLog(@"Convenience callback received (left)."); | ||
return YES; | ||
}]; | ||
CGRect frame = button.frame; | ||
frame.size.width += 20; | ||
button.frame = frame; | ||
[result addObject:button]; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
-(NSArray *) createRightButtons: (int) number | ||
{ | ||
NSMutableArray * result = [NSMutableArray array]; | ||
NSString* titles[2] = {@"Delete", @"More"}; | ||
UIColor * colors[2] = {[UIColor redColor], [UIColor lightGrayColor]}; | ||
for (int i = 0; i < number; ++i) | ||
{ | ||
MGSwipeButton * button = [MGSwipeButton buttonWithTitle:titles[i] backgroundColor:colors[i] callback:^BOOL(MGSwipeTableCell * sender){ | ||
NSLog(@"Convenience callback received (right)."); | ||
return YES; | ||
}]; | ||
[result addObject:button]; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; | ||
{ | ||
return tests.count; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
MGSwipeTableCell * cell; | ||
|
||
if (_testingStoryboardCell) { | ||
/** | ||
* Test using storyboard and prototype cell that uses autolayout | ||
**/ | ||
cell = [self.tableView dequeueReusableCellWithIdentifier:@"prototypeCell"]; | ||
} | ||
else { | ||
/** | ||
* Test using programmatically created cells | ||
**/ | ||
static NSString * reuseIdentifier = @"programmaticCell"; | ||
cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; | ||
if (!cell) { | ||
cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; | ||
} | ||
} | ||
|
||
TestData * data = [tests objectAtIndex:indexPath.row]; | ||
|
||
cell.textLabel.text = data.title; | ||
cell.textLabel.font = [UIFont systemFontOfSize:16]; | ||
cell.detailTextLabel.text = data.detailTitle; | ||
cell.delegate = self; | ||
cell.leftSwipeSettings.transition = data.transition; | ||
cell.rightSwipeSettings.transition = data.transition; | ||
cell.leftExpansion.buttonIndex = data.leftExpandableIndex; | ||
cell.leftExpansion.fillOnTrigger = NO; | ||
cell.rightExpansion.buttonIndex = data.rightExpandableIndex; | ||
cell.rightExpansion.fillOnTrigger = YES; | ||
|
||
#if !TEST_USE_MG_DELEGATE | ||
cell.leftButtons = [self createLeftButtons:data.leftButtonsCount]; | ||
cell.rightButtons = [self createRightButtons:data.rightButtonsCount]; | ||
#endif | ||
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | ||
|
||
return cell; | ||
} | ||
|
||
#if TEST_USE_MG_DELEGATE | ||
-(NSArray*) swipeTableCell:(MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction | ||
{ | ||
TestData * data = [tests objectAtIndex:[self.tableView indexPathForCell:cell].row]; | ||
if (direction == MGSwipeDirectionLeftToRight) { | ||
return [self createLeftButtons:data.leftButtonsCount]; | ||
} | ||
else { | ||
return [self createRightButtons:data.rightButtonsCount]; | ||
} | ||
} | ||
#endif | ||
|
||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return 60; | ||
} | ||
|
||
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion | ||
{ | ||
NSLog(@"Delegate: button tapped, %@ position, index %d, from Expansion: %@", | ||
direction == MGSwipeDirectionLeftToRight ? @"left" : @"right", (int)index, fromExpansion ? @"YES" : @"NO"); | ||
|
||
if (direction == MGSwipeDirectionRightToLeft && index == 0) { | ||
//delete button | ||
NSIndexPath * path = [self.tableView indexPathForCell:cell]; | ||
[tests removeObjectAtIndex:path.row]; | ||
[self.tableView deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationLeft]; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
@end |
53 changes: 53 additions & 0 deletions
53
demo/MGSwipeDemo/Images.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"size" : "76x76", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
demo/MGSwipeDemo/Images.xcassets/LaunchImage.launchimage/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "iphone", | ||
"subtype" : "retina4", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "ipad", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"orientation" : "landscape", | ||
"idiom" : "ipad", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"orientation" : "portrait", | ||
"idiom" : "ipad", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"orientation" : "landscape", | ||
"idiom" : "ipad", | ||
"extent" : "full-screen", | ||
"minimum-system-version" : "7.0", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Oops, something went wrong.