ios - Xcode slide and delete -


this code task recorder. works fine want slide , delete feature in cells. can in music or email applications. how can edit current code each cell added can slid on , delete button pops up. have seen example of code not understand how integrate mine.

my .h:

#import <uikit/uikit.h>  nsstring *docpath(void);   @interface bnrappdelegate : uiresponder  <uiapplicationdelegate, uitableviewdatasource> {   uitableview *tasktable;     uitextfield *taskfield;     uibutton *insertbutton;     uibutton *clearbutton;       nsmutablearray *tasks; }  - (void)addtask:(id)sender; - (void)taketask:(id)sender;     @property (strong, nonatomic) uiwindow *window;  @end 

this .m

#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 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 ^^^ add void. in void use 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 nsmutablearrays , how take dada 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)applicationwillresignactive:(uiapplication *)application { /*      sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone call or sms message) or when user quits application , begins transition background state.  use method pause ongoing tasks, disable timers, , throttle down opengl es frame rates. games should use method pause game.  */ }  - (void)applicationdidenterbackground:(uiapplication *)application { [tasks writetofile:docpath()         atomically:yes];   }  - (void)applicationwillenterforeground:(uiapplication *)application {     /*      called part of transition background inactive state; here     can undo many of changes made on entering background.      */ }  - (void)applicationdidbecomeactive:(uiapplication *)application { /*      restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user     interface.  */ }   - (void)applicationwillterminate:(uiapplication *)application { [tasks writetofile:docpath()         atomically:yes];}  @end 

this im trying doesnt work:

-(void)tableview:(uitableview *)table commiteditingstyle:       (uitableviewcelleditingstyle)editingstyle forrowatindexpath:  (nsindexpath *)indexpath  {         if (editingstyle == uitableviewcelleditingstyledelete)      {           [tasks removeobjectatindex:indexpath.row];     }  } 

in code, add following function

- (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath  {     return yes; } 

and

- (void)tableview:(uitableview *)table commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath  {         if (editingstyle == uitableviewcelleditingstyledelete)      {          //go ahead , delete row data     } } 

in function commiteditingstyle, have remove actual cell data example if have nsmutablearray contains cell data have delete actual object following [arr removeobjectatindex:indexpath.row];


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -