ios - UITableView Navigation not working -


i have following hierarchy in app navigation controller isn't working. when go hierarchy in storyboard, higher level tableview controllers blank instead of showing previous view.

uitabbarcontroller         uinavigationcontroller                 uitableviewcontroller                 uitableviewcontroller                 detailviewcontroller 

here's code tableview controller

@interface exercisetableviewcontroller ()  @end  @implementation exercisetableviewcontroller   - (void)viewdidload {      uibarbuttonitem *add = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action:@selector(addexercise:)];     self.navigationitem.rightbarbuttonitem = add;      nslog(@"level: %i, currentsmid: %i, currentmid: %i", _level, _currentsmid, _currentmid);      if (self.managedobjectcontext_ == nil) {         self.managedobjectcontext_ = [(appdelegate *)[[uiapplication sharedapplication] delegate] managedobjectcontext];     }      if (_level == 1) {         _submusclenamearray = [self submusclegroup:_currentmid valueforkeypath:@"submusclegroup"];         _submuscleidarray = [self submusclegroup:_currentmid valueforkeypath:@"submuscleid"];     } else if (_level == 2) {         //loading , sorting exercise list         _exerciselist = [self loadexercise:_currentmid sub:_currentsmid];         _exerciselistsorted = [self sortkeysbyname];     } else {         [self loadmusclegroup];     }      [super viewdidload];      // uncomment following line preserve selection between presentations.     // self.clearsselectiononviewwillappear = no;      // uncomment following line display edit button in navigation bar view controller.     // self.navigationitem.rightbarbuttonitem = self.editbuttonitem; }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  #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.     nsinteger count;      if (_level == 0) {         count = [_musclenamearray count];     } else if (_level == 1) {         count = [_submusclenamearray count];     } else {         count = [_exerciselist count];     }      return count; }   - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     if (_level == 0) {         int muscleid = [_muscleidarray[indexpath.row] intvalue];         nslog(@"muscleid: %i", muscleid);         nsarray *submusclearray = [self submusclegroup:muscleid valueforkeypath:@"submuscleid"];         if (submusclearray == nil || [submusclearray count] == 0) {              _currentmid = muscleid;             _level = 2;             _detailtitle = _musclenamearray[indexpath.row];                     nslog(@"title: %@", _detailtitle);             [self performseguewithidentifier:@"drilldown2" sender:self];         } else {             _currentmid = muscleid;             _level = 1;             _detailtitle = _musclenamearray[indexpath.row];                     nslog(@"title: %@", _detailtitle);         [self performseguewithidentifier:@"drilldown" sender:self];         }      } else if (_level == 1) {          _level = 2;         _currentsmid = [_submuscleidarray[indexpath.row] intvalue];         _detailtitle = _submusclenamearray[indexpath.row];         [self performseguewithidentifier:@"drilldown2" sender:self];      } else {         _detailtitle = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:0];         _equipment = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:1];         _image = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:2];         _imagenumber =  [[[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:3] intvalue];         _levelstring = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:4];         _status = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:5];         _thumbnail = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:6];         _type = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:7];         _unitofmeasure = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:8];         _video = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:9];         _workoutdirections = [[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:10];         _exerciseid = [[_exerciselistsorted objectatindex:indexpath.row] intvalue];          [self performseguewithidentifier:@"showexercisedetail" sender:self];      }   }  - (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section {     return nil; }   - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"drilldowncell";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }     if (_level == 0) {         [[cell textlabel] settext:[_musclenamearray objectatindex:indexpath.row]];     } else if (_level == 1) {         [[cell textlabel] settext:[_submusclenamearray objectatindex:indexpath.row]];     } else {         [[cell textlabel] settext:[[_exerciselist valueforkey:[_exerciselistsorted objectatindex:indexpath.row]] objectatindex:0]];     }      return cell;  }  - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {      return nil; }   #pragma mark -  #pragma data retrieval methods  -(nsarray *) sortkeysbyname{      //method of nsdictionary class sorts keys using logic given comparator block     nsarray * sortarray = [_exerciselist keyssortedbyvalueusingcomparator: ^(id obj1, id obj2) {          //we case insensitive comparision of 2 strings not concerned         //the "content" of strings (please see sortkeysonthebasisofnationalincome method         //we comparision numeric search option)         nscomparisonresult result = [[obj1 objectatindex:0] caseinsensitivecompare:[obj2 objectatindex:0]];         return result;     }];      //show result in output panel     (int = 0; < [sortarray count]; i++) {         nslog(@"workoutid:%@, workoutname:%@",[sortarray objectatindex:i], [[_exerciselist valueforkey:[sortarray objectatindex:i]] objectatindex:0]);     }      return sortarray; }  - (void)loadmusclegroup{     nsfetchrequest *request = [[nsfetchrequest alloc] init];     //this needed because quizviewcontroller isn't first level view. managedobjectcontext nil before declaration     nsentitydescription *entity = [nsentitydescription entityforname:@"muscle_group"                                               inmanagedobjectcontext:_managedobjectcontext_];     [request setentity:entity];     nserror *error;     _musclearray = [[_managedobjectcontext_ executefetchrequest:request error:&error] mutablecopy];     nssortdescriptor *musclesort = [[nssortdescriptor alloc] initwithkey:@"musclegroup" ascending:yes];     [_musclearray sortusingdescriptors:[nsmutablearray arraywithobject:musclesort]];     _musclenamearray = [_musclearray valueforkeypath:@"musclegroup"];     _muscleidarray = [_musclearray valueforkeypath:@"muscleid"]; //    nslog(@"muscleidarray count:%i, musclenamearray count:%i, muscleid1: %d, muscleid2: %d", [_muscleidarray count], [_musclenamearray count], _muscleidarray[1], _muscleidarray[2]); }  - (nsarray *)submusclegroup:(int)muscleid valueforkeypath:(nsstring *)string{     nsfetchrequest *request = [[nsfetchrequest alloc] init];     //this needed because quizviewcontroller isn't first level view. managedobjectcontext nil before declaration     nsentitydescription *entity = [nsentitydescription entityforname:@"submuscle_group"                                               inmanagedobjectcontext:_managedobjectcontext_];     nspredicate *predicate = [nspredicate predicatewithformat:@"muscleid = %i", muscleid];     nslog(@"muscleid = %i", muscleid);     [request setpredicate:predicate];     [request setentity:entity];     nserror *error;     nsmutablearray *submusclearray = [[_managedobjectcontext_ executefetchrequest:request error:&error] mutablecopy];     nssortdescriptor *submusclesort = [[nssortdescriptor alloc] initwithkey:@"submusclegroup" ascending:yes];     [submusclearray sortusingdescriptors:[nsmutablearray arraywithobject:submusclesort]];     nsarray *submusclegrouparray = [submusclearray valueforkeypath:string];     return submusclegrouparray; }  - (nsmutabledictionary *)loadexercise:(int)muscleid sub:(int)submuscleid{      //getting array workout muscle relationship table     nsfetchrequest *request = [[nsfetchrequest alloc] init];     nsentitydescription *entity = [nsentitydescription entityforname:@"workout_muscle_relationship"                                               inmanagedobjectcontext:_managedobjectcontext_];     nspredicate *predicate;     if (submuscleid != 0) {         predicate = [nspredicate predicatewithformat:@"muscleid = %i , submuscleid = %i", muscleid, submuscleid];     } else {         predicate = [nspredicate predicatewithformat:@"muscleid = %i", muscleid];     }      [request setpredicate:predicate];     [request setentity:entity];     nserror *error;     nsmutablearray *workoutrelationshiparray = [[_managedobjectcontext_ executefetchrequest:request error:&error] mutablecopy];     nssortdescriptor *workoutsort = [[nssortdescriptor alloc] initwithkey:@"workoutid" ascending:yes];     [workoutrelationshiparray sortusingdescriptors:[nsmutablearray arraywithobject:workoutsort]];     nsarray *workoutidarray = [workoutrelationshiparray valueforkeypath:@"workoutid"];       //getting array workout group table     nsfetchrequest *request2 = [[nsfetchrequest alloc] init];     nsentitydescription *entity2 = [nsentitydescription entityforname:@"workout_group_table"                                                inmanagedobjectcontext:_managedobjectcontext_];     [request2 setentity:entity2];     nsmutablearray *workoutarray = [[_managedobjectcontext_ executefetchrequest:request2 error:&error] mutablecopy];     nssortdescriptor *workoutsort2 = [[nssortdescriptor alloc] initwithkey:@"workoutid" ascending:yes];     [workoutarray sortusingdescriptors:[nsmutablearray arraywithobject:workoutsort2]];     nsarray *workoutidarray2 = [workoutarray valueforkeypath:@"workoutid"];     nsarray *workoutname = [workoutarray valueforkeypath:@"workoutname"];     nsarray *equipmentarray = [workoutarray valueforkeypath:@"equipment"];     nsarray *imagearray = [workoutarray valueforkeypath:@"image"];     nsarray *imagenumberarray = [workoutarray valueforkeypath:@"imagenumber"];     nsarray *levelstringarray = [workoutarray valueforkeypath:@"level"];     nsarray *statusarray = [workoutarray valueforkeypath:@"status"];     nsarray *thumbnailarray = [workoutarray valueforkeypath:@"thumbnail"];     nsarray *typearray = [workoutarray valueforkeypath:@"type"];     nsarray *unitofmeasurearray = [workoutarray valueforkeypath:@"unitofmeasure"];     nsarray *videoarray = [workoutarray valueforkeypath:@"video"];     nsarray *workoutdirectionsarray = [workoutarray valueforkeypath:@"workoutdirections"];     nsarray *workoutid = [workoutarray valueforkeypath:@"workoutid"];     nsarray *muscleimagearray = [workoutarray valueforkey:@"muscleimage"];      nsmutabledictionary *list = [nsmutabledictionary new];      nslog(@"workoutidarray count: %i, workoutidarray2 count: %i", [workoutidarray count], [workoutidarray2 count]);     int start = 0;      (int = 0; < [workoutidarray count]; ++) {         nslog(@"i:%i", i);         (int j = start; j < [workoutidarray2 count]; j++) {             nslog(@"j:%i",j);             if (workoutidarray[i] == workoutidarray2[j]) {                 nsarray *temp = [nsarray arraywithobjects:workoutname[j], equipmentarray[j], imagearray[j], imagenumberarray[j], levelstringarray[j], statusarray[j], thumbnailarray[j], typearray[j], unitofmeasurearray[j], videoarray[j], workoutdirectionsarray[j], workoutid[j], muscleimagearray[j], nil];                 nsstring *temp2 = [[nsstring alloc] initwithformat:@"%@", workoutidarray2[j]];                 [list setvalue:temp forkey:temp2];                 start = j;                 break;             }         }     }        return list;  }  - (nsstring *)getexerciseinfo:(int)eid valueforkeypah:(nsstring *)string{     nsstring *result;        return result; }  - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{       if ([segue.identifier isequaltostring:@"showexercisedetail"]) {         //exercisedetail *exercisedetail = (exercisedetail *)segue.destinationviewcontroller;         //exercisedetail.pagetitle = detailtitle;         //uinavigationcontroller *navcontroller = (uinavigationcontroller *)segue.destinationviewcontroller;         exercisedetail *exercisedetail = (exercisedetail *)segue.destinationviewcontroller;         exercisedetail.title = _detailtitle;         exercisedetail.exerciseid = _exerciseid;         exercisedetail.imagenumber = _imagenumber;         exercisedetail.image = _image;         exercisedetail.equipment = _equipment;         exercisedetail.levelstring = _levelstring;         exercisedetail.status = _status;         exercisedetail.thumbnail = _thumbnail;         exercisedetail.type = _type;         exercisedetail.unitofmeasure = _unitofmeasure;         exercisedetail.video = _video;         exercisedetail.workoutdirections = _workoutdirections;     } else if ([segue.identifier isequaltostring:@"drilldown"] || [segue.identifier isequaltostring:@"drilldown2"]){         //uinavigationcontroller *navcontroller = (uinavigationcontroller *)segue.destinationviewcontroller;         exercisetableviewcontroller *tableview = segue.destinationviewcontroller;         tableview.title = _detailtitle;         nslog(@"title: %@", _detailtitle);         tableview.delegate = self;         tableview.level = _level;         tableview.currentsmid = _currentsmid;         tableview.currentmid = _currentmid;         tableview.musclenamearray = _musclenamearray;         if (_level == 2) {             tableview.submusclenamearray = _submusclenamearray;         }         nslog(@"level: %i, currentsmid: %i, currentmid: %i", _level, _currentsmid, _currentmid);     } else if ([segue.identifier isequaltostring:@"addexercise"]){         uinavigationcontroller *navcontroller = (uinavigationcontroller *)segue.destinationviewcontroller;         addexerciseviewcontroller *addexercise = (addexerciseviewcontroller *)navcontroller.topviewcontroller;         addexercise.modaltransitionstyle = uimodaltransitionstylefliphorizontal;         } else if ([segue.identifier isequaltostring:@"dismissview"]){         [self dismissviewcontrolleranimated:yes completion:nil];     } }  - (void)addexercise:(id)sender {     [self performseguewithidentifier:@"addexercise" sender:sender]; }  - (void)viewdidappear:(bool)animated{     nslog(@"musclenamearray count: %i, submusclenamearray count: %i, exercistlist count: %i", [_musclenamearray count], [_submusclenamearray count], [_exerciselist count]);     [super viewdidappear:yes]; }  - (void)viewwillappear:(bool)animated{     [self.myworkoutlist reloaddata];     nslog(@"musclenamearray count: %i, submusclenamearray count: %i, exercistlist count: %i", [_musclenamearray count], [_submusclenamearray count], [_exerciselist count]);     [super viewwillappear:yes]; }  /* // override support conditional editing of table view. - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath *)indexpath {     // return no if not want specified item editable.     return yes; } */  /* // override support editing table view. - (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {     if (editingstyle == uitableviewcelleditingstyledelete) {         // delete row data source         [tableview deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade];     } else if (editingstyle == uitableviewcelleditingstyleinsert) {         // create new instance of appropriate class, insert array, , add new row table view     }    } */  /* // override support rearranging table view. - (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)fromindexpath toindexpath:(nsindexpath *)toindexpath { } */  /* // override support conditional rearranging of table view. - (bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath {     // return no if not want item re-orderable.     return yes; } */  /* #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. } */  @end 


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -