iphone - How to display the text of one tableview cell in the detailtextlabel of previous controller through array -


i have created  controller class named taddalarmcontroller has  tableview consists of 6 rows .when click on second row navigates page new controller name talarmnewcontroller tableviewcontroller , in have created nsmutablearray , populated array 7 static values when second controller displayed tableview displayed 7 static values in it.i want when click on  row of second controller value present inside cell of paticular row should set detailtextlabel of previouscontroller i.e taddalarmcontroller .please me in solving problem.this code:      addalarmcontroller.h     #import <uikit/uikit.h>      @class stopsnoozeappdelegate;     @class alarm;     @class talarmnewcontroller;     @interface taddalarmcontroller : uitableviewcontroller {          stopsnoozeappdelegate *app;         iboutlet uitableview *tblview;         nsdateformatter *dateformatter;         nsundomanager *undomanager;         alarm *am;         talarmnewcontroller *anew;     }     @property(nonatomic,retain)nsdateformatter *dateformatter;     @property (nonatomic,retain)alarm *am;     @property (nonatomic,retain)nsundomanager *undomanager;     @end       .m file         #import "taddalarmcontroller.h"      #import "alarm.h"     #import "talarmnewcontroller.h"       @implementation taddalarmcontroller     @synthesize dateformatter;     @synthesize am;     @synthesize undomanager;        #pragma mark -     #pragma mark view lifecycle         - (void)viewdidunload {         // release properties loaded in viewdidload or can recreated lazily.         self.dateformatter = nil;     }       - (void)viewwillappear:(bool)animated {         [super viewwillappear:animated];         [self.tableview reloaddata];      }       #pragma mark -     #pragma mark table view data source      - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {         // return number of sections.         return 1;     }       - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {         // return number of rows in section.         return 6;     }       - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath     {         return 44;     }         - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {          static nsstring *cellidentifier = @"cell";         /*          dequeue or create , configure table cell each attribute of book.          */         uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];         if (cell == nil) {             cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:cellidentifier] autorelease];             //cell.editingaccessorytype = uitableviewcellaccessorydisclosureindicator;             cell.accessorytype = uitableviewcellaccessorydisclosureindicator;         }           switch (indexpath.row) {             case 0:                  cell.textlabel.text = @"time";                 break;             case 1:                  cell.textlabel.text = @"repeat";                 break;             case 2:                 cell.textlabel.text = @"sound";                 break;              case 3:                 cell.textlabel.text = @"snooze interval";                 break;              case 4:                 cell.textlabel.text = @"alarm message";                 break;              case 5:                 cell.textlabel.text = @"snooze penalty";                 break;         }         return cell;     }         #pragma mark -     #pragma mark table view delegate      - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath     {             talarmnewcontroller *controller = [[talarmnewcontroller alloc]initwithnibname:@"talarmnewcontroller" bundle:nil];          switch (indexpath.row) {             case 0:                 controller.editedobject = @"time";                  break;             case 1:                  [self.navigationcontroller pushviewcontroller:controller animated:yes];                 [controller release];              default:                 break;         }       }         - (nsdateformatter *)dateformatter {             if (dateformatter == nil) {             dateformatter = [[nsdateformatter alloc] init];             //[dateformatter setdatestyle:nsdateformattermediumstyle];             [dateformatter settimestyle:nsdateformatternostyle];         }         return dateformatter;     }      - (void)dealloc {         [super dealloc];     }       @end       talarmnewcontroller.h        @class taddalarmcontroller;      @interface talarmnewcontroller : uitableviewcontroller {         iboutlet uitableview *tblview;         uidatepicker *datepicker;         id editedobject;               taddalarmcontroller *addalarm;           nsmutablearray *days;//this array storing 7 values statically      }     @property (nonatomic,retain) iboutlet uitableview *tblview;     @property(nonatomic,retain) iboutlet uidatepicker *datepicker;      @property (nonatomic, retain) id editedobject;     @property(nonatomic,retain)nsmutablearray *days;     @property (nonatomic, retain, readonly) taddalarmcontroller *addalarm;     -(ibaction)cancel;     -(ibaction)save;     @end        .m file      #import "talarmnewcontroller.h"      #import "taddalarmcontroller.h"       @implementation talarmnewcontroller      @synthesize  editedobject,datepicker, tblview,days,addalarm;      #pragma mark -     #pragma mark view lifecycle       - (void)viewdidload {          uibarbuttonitem * savebutton = [[uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemsave target:self action:@selector(save)];         self.navigationitem.rightbarbuttonitem = savebutton;         [savebutton release];          uibarbuttonitem *cancelbutton = [[uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemcancel target:self action:@selector(cancel)];         self.navigationitem.leftbarbuttonitem = cancelbutton;         [cancelbutton release];          days =[[nsmutablearray alloc]initwithobjects:@"every monday",@"every tuesday",@"every wednesday",@"every thursday",@"every friday",@"every saturday",@"every sunday0",nil];          [super viewdidload];       }       - (taddalarmcontroller *)addalarm {         if (addalarm == nil) {             addalarm = [[taddalarmcontroller alloc] initwithstyle:uitableviewstylegrouped];         }         return addalarm;     }        -(ibaction)save{          [self.navigationcontroller popviewcontrolleranimated:yes];     //     }      -(ibaction)cancel{         [self.navigationcontroller popviewcontrolleranimated:yes];     }        #pragma mark -     #pragma mark table view data source      - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {         // return number of sections.         return 1;     }       - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {         // return number of rows in section.         return [days count];     }       // customize appearance of table view cells.     - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {          static nsstring *cellidentifier = @"cell";          uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];         if (cell == nil) {             cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];         }          cell.textlabel.text = [days objectatindex:indexpath.row];         // configure cell...          return cell;     }          #pragma mark -     #pragma mark table view delegate      - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      }         - (void)dealloc {         [datepicker release];          [super dealloc];     }       @end 

in firstviewcontroller

1, keep member variable(nsstring) named detailtextvaluefromsecondcontroller.

2, create function named

-(void)refreshtabletosetdetailtext:(nsstring *)detailtextvalue 

then in secondviewcontroller

inside

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath 

place following code:

for (int =0; < [[self.navigationcontroller viewcontrollers] count]; i++)             {                 uiviewcontroller *acontroller = [[self.navigationcontroller viewcontrollers] objectatindex:i];                  if ([acontroller iskindofclass:[firstviewcontroller class]])                 {                    firstviewcontroller *afirstviewcontroller = (firstviewcontroller *)acontroller;                    [afirstviewcontroller refreshtabletosetdetailtext:yourstringtosetondetaillabel];         [self.navigationcontroller poptoviewcontroller:acontroller animated:yes];                 }       } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -