title: Xcode slide and delete
body: <p>This is my code for a task recorder. It works fine I just want to but the slide and delete feature in my cells. Like what you can do in the music or email applications. How can I edit my current code so that each cell that is added can be slid over and then the delete button pops up. I have seen example of the code but I do not understand how to integrate it into mine. </p>
  
  <p>My .h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  NSString *docPath(void); 
  
  @interface BNRAppDelegate : UIResponder 
  &lt;UIApplicationDelegate, UITableViewDataSource&gt;
  {
  
      UITableView *taskTable;
      UITextField *taskField;
      UIButton *insertButton;
      UIButton *clearButton;
  
      NSMutableArray *tasks;
  }
  
  - (void)addTask:(id)sender;
  - (void)takeTask:(id)sender;
  
  
  @property (strong, nonatomic) UIWindow *window;
  
  @end
  </code></pre>
  
  <p>This is my .m</p>
  
  <pre><code>#import "BNRAppDelegate.h"
  
  
  NSString *docPath()
  {
      NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                              NSUserDomainMask,
                                                              YES);
      return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"data.td" ];
  }    
  
  @implementation BNRAppDelegate
  
  @synthesize window = _window;
  
  #pragma mark - Application delegate callbacks
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:                 (NSDictionary *)launchOptions
  {
      NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
      if (plist)
      {
          tasks = [plist mutableCopy];
      }
      else
      {
          tasks = [[NSMutableArray alloc] init];
      }
  
      CGRect windowFrame = [[UIScreen mainScreen] bounds];
      UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
      [self setWindow:theWindow];
  
      CGRect tableFrame = CGRectMake(0, 80, 320, 380);
      CGRect fieldFrame = CGRectMake(5, 40, 180, 31);
      CGRect buttonFrame = CGRectMake(190, 40, 60, 31);
      CGRect clearFrame = CGRectMake(255, 40 , 60, 30); 
  
  
      taskTable = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
      [taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
      [taskTable setDataSource:self];
  
  
      taskField = [[UITextField alloc] initWithFrame:fieldFrame];
      [taskField setBorderStyle:UITextBorderStyleRoundedRect];
      [taskField setPlaceholder:@"Type a task, tap Insert"];
  
  
      insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      [insertButton setFrame:buttonFrame];
      [insertButton addTarget:self action:@selector(addTask:) forControlEvents:UIControlEventTouchUpInside];
      [insertButton addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
      [insertButton setTitle:@"Insert" forState:UIControlStateNormal];
  
  
      clearButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      [clearButton setFrame:clearFrame];
      [clearButton addTarget:self action:@selector(takeTask:)     forControlEvents:UIControlEventTouchUpInside];
      [clearButton setTitle:@"Clear" forState:UIControlStateNormal];
  
  
       //For Clear make simular to ^^^ then add void. In Void use the variable t.               
  
      [[self window] addSubview:taskTable];
      [[self window] addSubview:taskField];
      [[self window] addSubview:insertButton];
      [[self window] addSubview:clearButton];
  
      [[self window] setBackgroundColor:[UIColor whiteColor]];
      [[self window] makeKeyAndVisible];
  
      return YES;
  }
  - (void)addTask:(id)sender
  {
      NSString *t=[taskField text];
  
      if ([t isEqualToString:@""]) {
          return;
      }
  
      [tasks addObject:t];
      [taskTable reloadData];
      [taskField setText:@""];
      [taskField resignFirstResponder];
  } 
  
  - (void)takeTask:(id)sender
  {
      //LEARN ABOUT NSMUTABLEARRAYS AND HOW TO TAKE DADA FROM THEM
      [tasks removeAllObjects];
      [taskTable reloadData];
      [tasks writeToFile:docPath()
              atomically:YES];
  }
  
  
  #pragma mark - Table View management
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      return [tasks count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
  
  {
      UITableViewCell *c= [taskTable dequeueReusableCellWithIdentifier:@"Cell"];
  
      if (!c) {
          c= [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
      }
  
      NSString *item = [tasks objectAtIndex:[indexPath row]];
      [[c textLabel] setText:item];
  
      return c;
  } 
  
  
  - (void)applicationDidEnterBackground:(UIApplication *)application
  {
      [tasks writeToFile:docPath()
              atomically:YES];
  }
  
  - (void)applicationWillTerminate:(UIApplication *)application
  {
      [tasks writeToFile:docPath()
              atomically:YES];
  }
  
  @end
  </code></pre>
  
  <p>This is what im trying but it doesn't work:</p>
  
  <pre><code>-(void)tableView:(UITableView *)table commitEditingStyle:       (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:  (NSIndexPath *)indexPath 
  {    
      if (editingStyle == UITableViewCellEditingStyleDelete) 
      {
            [tasks removeObjectAtIndex:indexPath.row];
      }
  }
  </code></pre>