Commits

Alfonso Alba García committed 892f6d2

Deleting groups by swiping a cell in the groups table

  • Participants
  • Parent commits 38934f4

Comments (0)

Files changed (2)

ParseTest/PTAddGroupViewController.xib

 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">42</int>
+			<int key="maxID">43</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes"/>
 		<int key="IBDocument.localizationMode">0</int>

ParseTest/PTGroupsViewController.m

 
 #import "PTGroupsViewController.h"
 #import "PTAddGroupViewController.h"
+#import "PTAppDelegate.h"
 #import <Parse/Parse.h>
 @interface PTGroupsViewController ()
 
     
 }
 
+
 - (void)didReceiveMemoryWarning
 {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
 }
 
+#pragma mark UITableViewDataSourceProtocol
+
 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return [groups count];
 }
     return cell;
 }
 
+-(BOOL) tableView:(UITableView *)tableView canDeleteRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    return YES;
+}
+- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    return UITableViewCellEditingStyleDelete;
+}
+
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    if (editingStyle == UITableViewCellEditingStyleDelete) {
+        PFObject *group = [groups objectAtIndex:indexPath.row];
+        [group deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
+            if(succeeded & !error)
+            {
+                NSMutableArray *newGroups = [groups mutableCopy];
+                [newGroups removeObjectAtIndex:indexPath.row];
+                groups = [newGroups copy];
+                dispatch_async(dispatch_get_main_queue(), ^{
+                    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];                
+                });
+            }
+        }];
+    }
+}
+
+#pragma mark Actions
 
 - (void) addGroupAction
 {