ios - I don't know why my Tableview did not push the DetailView when row is selected -


i find sample code , modified code make want. tableview load data plist, works datas displayed in sections, works when row selected, want push detailviewcontroller show more details. grrrr, not work, , don't know why. difference between code , other 1 works fine, icb_sectionedtableviewdemoviewcontroller declared class in appdelegate , don't know if incidence when want push detailviewcontroller.

here code of rootcontroller named icb_sectionedtableviewdemoviewcontroller.m

//  icb_sectionedtableviewdemoviewcontroller.m //  icb_sectionedtableviewdemo // //  created matt tuzzolo on 12/10/10. //  copyright 2010 elc technologies. rights reserved. //  #import "icb_sectionedtableviewdemoviewcontroller.h" #import "icb_sectionedtableviewdemoappdelegate.h" #import "detailviewcontroller.h"    @implementation icb_sectionedtableviewdemoviewcontroller  @synthesize books, sections ;  - (void)viewdidload {      self.books = [nsmutablearray arraywithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"books" oftype:@"plist"]];     self.sections = [[nsmutabledictionary alloc] init];      bool found;      // loop through books , create our keys     (nsdictionary *book in self.books)     {                 nsstring *c = [[book objectforkey:@"author"] substringtoindex:1];          found = no;          (nsstring *str in [self.sections allkeys])         {             if ([str isequaltostring:c])             {                 found = yes;             }         }          if (!found)         {                  [self.sections setvalue:[[nsmutablearray alloc] init] forkey:c];         }     }      // loop again , sort books respective keys     (nsdictionary *book in self.books)     {         [[self.sections objectforkey:[[book objectforkey:@"author"] substringtoindex:1]] addobject:book];     }          // sort each section array     (nsstring *key in [self.sections allkeys])     {         [[self.sections objectforkey:key] sortusingdescriptors:[nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"author" ascending:yes]]];     }          [super viewdidload]; }  #pragma mark - #pragma mark table view data source  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview  {     return [[self.sections allkeys] count]; }  - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {         if(section == 0)         return @"couleurs";     else         return @"motifs";        //  return [[[self.sections allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)] objectatindex:section]; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section  {     return [[self.sections valueforkey:[[[self.sections allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)] objectatindex:section]] count]; }  - (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview {     return [[self.sections allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)]; }  // 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:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease];     }      nsdictionary *book = [[self.sections valueforkey:[[[self.sections allkeys] sortedarrayusingselector:@selector(localizedcaseinsensitivecompare:)] objectatindex:indexpath.section]] objectatindex:indexpath.row];      cell.textlabel.text = [book objectforkey:@"title"];         cell.detailtextlabel.text = [book objectforkey:@"description"];      return cell; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {        //initialize detail view controller , display it.     detailviewcontroller *dvcontroller = [[detailviewcontroller alloc] initwithnibname:@"detailview" bundle:[nsbundle mainbundle]];     dvcontroller.cl = [self.books objectatindex:indexpath.row];     [self.navigationcontroller pushviewcontroller:dvcontroller animated:yes];  //   [self presentmodalviewcontroller:dvcontroller animated:yes];  //   [self.view addsubview:dvcontroller.view];     [dvcontroller release];    }   - (void)didreceivememorywarning {     // releases view if doesn't have superview.     [super didreceivememorywarning];      // release cached data, images, etc aren't in use. }  - (void)viewdidunload {     // release retained subviews of main view.     // e.g. self.myoutlet = nil; }   - (void)dealloc {     [super dealloc]; }  @end 

thanks useful , remind i'm beginner , first language franch.

after having @ project, seems did not create uinavigationcontroller. so, suggest use code application:didfinishlaunchingwithoptions::

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {          uinavigationcontroller* navigation = [[uinavigationcontroller alloc] init];     [navigation pushviewcontroller:viewcontroller animated:no];     [window addsubview:navigation.view];      [self.window makekeyandvisible];      return yes;  } 

here, uinavigationcontroller instantiated , first (root) controller pushed on it.

important: app has more problems, not work, @ least detailview controller loaded , attempted display. issues found:

  1. in didselectrowatindexpath using wrong nib name;

  2. in detailviewcontroller's viewdidload using property cl.title not defined;

once fix problems, possibly detail view show up.

old answer:

set breakpoint in tableview:didselectrowatindexpath: , check detailviewcontroller created correctly , self.navigationcontroller not nil.

alternatively can add nslog traces code (this important debugging technique):

 - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      //initialize detail view controller , display it.     detailviewcontroller *dvcontroller = [[detailviewcontroller alloc] initwithnibname:@"detailview" bundle:[nsbundle mainbundle]];     dvcontroller.cl = [self.books objectatindex:indexpath.row];     [self.navigationcontroller pushviewcontroller:dvcontroller animated:yes];      nslog(@"navcontroller: %@", [self.navigationcontroller description]);     nslog(@"dvcontroller.cl: %@", [dvcontroller.cl description]);    //   [self presentmodalviewcontroller:dvcontroller animated:yes];  //   [self.view addsubview:dvcontroller.view];    [dvcontroller release];  } 

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 -