objective c - Label data is erased when I back to the screen from tableview in iOS -


here json response label value.

{         "dry_cleaning" = 49;         iron = 8;         name = "shirt/tees";         wash = 15;         "wash_iron" = 19;         counts = 2;         id = 1;         total = 98;     },         {         "dry_cleaning" = 49;         iron = 5;         name = "kurta(short)";         wash = 20;         "wash_iron" = 19;         counts = 2;         id = 2;         total = 98;     },         {         "dry_cleaning" = 50;         iron = 8;         name = "kurta(long)";         wash = 15;         "wash_iron" = 20;         counts = 0;         id = 3;     },         {         "dry_cleaning" = 50;         iron = 5;         name = shorts;         wash = 15;         "wash_iron" = 19;         counts = 0;         id = 4;     },         {         "dry_cleaning" = 55;         iron = 8;         name = "trousers/pyjamas";         wash = 20;         "wash_iron" = 30;         counts = 0;         id = 5;     },         {         "dry_cleaning" = 70;         iron = 7;         name = jeans;         wash = 20;         "wash_iron" = 29;         counts = 0;         id = 6;     },         {         "dry_cleaning" = 150;         iron = 5;         name = blazer;         wash = 25;         "wash_iron" = 19;         counts = 0;         id = 7;     },         {         "dry_cleaning" = 100;         iron = 6;         name = "leather_jacket";         wash = 30;         "wash_iron" = 36;         counts = 0;         id = 8;     },         {         "dry_cleaning" = 100;         iron = 13;         name = "lungi/dhoti(long)";         wash = 12;         "wash_iron" = 15;         counts = 0;         id = 9;     }, 

here first screenshot:

enter image description here

i complete increment in specific cell. when click place order button display total amount screen.

second screenshot:

enter image description here

third screenshot:

when screen stepper label value zero. want editable value in specific cell.

enter image description here

here code.

order.h

#import <uikit/uikit.h> #import "customcell.h" @interface order : uiviewcontroller<uitableviewdatasource,uitableviewdelegate,uitextfielddelegate> @property (weak, nonatomic) iboutlet uitableview *tableview;   - (ibaction)placeorder:(id)sender;  @property (weak, nonatomic) iboutlet uibutton *btn_placeorder;  @end 

order.m

// //  order.m //  laundryapp // //  created tranetech on 13/01/16. //  copyright (c) 2016 tranetech. rights reserved. //  #import "order.h" #import "customcell.h" #import "totalamount.h" #import "globalvariabe.h"  @interface order ()  @end  @implementation order  {     nsdictionary *dic_property;     // nsarray *dic_property;     nsmutabledictionary *data; }  - (void)viewdidload {     [super viewdidload];      [self.tableview reloaddata];     globalvariabe *global=[globalvariabe sharedinstance];     [nsthread detachnewthreadselector:@selector(fetchdata) totarget:self withobject:nil];      global.arraycounts = [nsmutablearray array];     //  nslog(@"array count=%lu",(unsigned long)global.arraycounts.count);    //    [self.tableview registernib:[uinibnibwithnibname:@"customcell"bundle:nil] forcellreuseidentifier:@"cell"];     // additional setup after loading view. }  -(void)fetchdata {     nsstring *login= [[nsstring stringwithformat:@"http:/men_dry.php"]stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];      nslog(@"----%@", login);     nsurl *url = [nsurl urlwithstring:[login stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];     //-- request , response though url     nsmutableurlrequest *request = [[nsmutableurlrequest alloc]initwithurl:url];       [nsurlconnection sendasynchronousrequest:request                                        queue:[nsoperationqueue mainqueue]                            completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {                                dispatch_async(dispatch_get_main_queue(), ^{                                    if (data) {                                        dic_property= [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers error:nil];                                        nslog(@"%@", dic_property);                                        //                                       nslog(@"counts=%d",[[dic_property objectforkey:@"data"]count]);                                        //                                       (int = 0; i<[[dic_property objectforkey:@"data"] count]; i++) {                                        //                                                   [self.arraycounts insertobject:[nsstring stringwithformat:@"0"] atindex:i];                                        //                                               }                                        nsarray *temparray = dic_property[@"data"];                                        (int i=0; i<temparray.count; i++) {                                            nsmutabledictionary *dictvalues = [nsmutabledictionary dictionarywithdictionary:temparray[i]];                                            [dictvalues setvalue:@"0" forkey:@"counts"];                                            globalvariabe *global=[globalvariabe sharedinstance];                                            [global.arraycounts addobject:dictvalues];                                        }                                        [self.tableview reloaddata];                                    }                                    else {                                        nslog(@"network error, %@", [error localizedfailurereason]);                                    }                                });                             }];   }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return 100; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     globalvariabe *global=[globalvariabe sharedinstance];      return global.arraycounts.count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *simpletableidentifier = @"simpletableitem";      customcell *cell = (customcell *)[self.tableview dequeuereusablecellwithidentifier:simpletableidentifier];     if (cell == nil)         cell = [[[nsbundle mainbundle] loadnibnamed:@"customcell" owner:self options:nil] objectatindex:0];      globalvariabe *global=[globalvariabe sharedinstance]; //    nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; //    nsmutablearray *test=[userdefaults objectforkey:@"finalarray"];     cell.lbl_value.text = [nsstring stringwithformat:@"%@",global.arraycounts[indexpath.row][@"counts"]];     nslog(@"strainfffdf=%@",[nsstring stringwithformat:@"%@",global.arraycounts[indexpath.row][@"counts"]]);     cell.lbl_title.text=[nsstring stringwithformat:@"%@",global.arraycounts[indexpath.row][@"name"]];      cell.lbl_price.text=[nsstring stringwithformat:@"%@",global.arraycounts[indexpath.row][@"dry_cleaning"]];     cell.txt1.text=[nsstring stringwithformat:@"%@",global.arraycounts[indexpath.row][@"counts"]];     [cell.stepper addtarget:self action:@selector(itemschange:) forcontrolevents:uicontroleventvaluechanged];     return cell;     }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {  } - (void)itemschange:(uistepper*)stepper {     cgpoint cursorposition = [stepper convertpoint:cgpointzero toview:self.tableview];     nsindexpath *indexpath = [self.tableview indexpathforrowatpoint:cursorposition];      customcell *currentcell = (customcell *)[self.tableview cellforrowatindexpath:indexpath];      double value = [stepper value];     int x = [currentcell.lbl_value.text intvalue];     int price=[currentcell.lbl_price.text intvalue];     int y= x * price;      [currentcell.lbl_value settext:[nsstring stringwithformat:@"%d", (int)value]];     currentcell.txt1.text=[nsstring stringwithformat:@"%d", (int)value];      globalvariabe *global=[globalvariabe sharedinstance];     global.arraycounts[indexpath.row][@"counts"] = [nsstring stringwithformat:@"%d",(int)value];     global.arraycounts[indexpath.row][@"total"] = [nsstring stringwithformat:@"%d",(int)y];  }  /* #pragma mark - navigation  // in storyboard-based application, want little preparation before navigation - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     // new view controller using [segue destinationviewcontroller].     // pass selected object new view controller. } */  - (ibaction)placeorder:(id)sender {     nspredicate *predicate = [nspredicate predicatewithformat:@"counts != %@",@"0"];     globalvariabe *global=[globalvariabe sharedinstance];      nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults];     global.filteredarray = [global.arraycounts filteredarrayusingpredicate:predicate];     nslog(@"button click event=%@",global.arraycounts);        if(global.filteredarray.count > 0)     {      [userdefaults setobject:global.filteredarray forkey:@"def_orderarraylist"];         [userdefaults setobject:global.arraycounts forkey:@"finalarray"];     [userdefaults synchronize];     }   //  nslog(@"value:%@",global.filteredarray);     nslog(@"default array=%@",[userdefaults objectforkey:@"finalarray"]);     totalamount *nextpage=[self.storyboard instantiateviewcontrollerwithidentifier:@"totalamountpage"];     [self presentviewcontroller:nextpage animated:yes completion:nil];   } @end 

how editable label value when return screen?

instead of calling fetchdata method in -(void)viewdidload method, should call method in -(void)viewwillappear:(bool)animated method. , use [self.navigationcontroller popviewcontrolleranimated:yes] go viewcontroller.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -