ios - Accessing a UITableView when a UINavigationController gets in the way (in a UISplitViewController) -


i have uisplitviewcontroller set so:

-(ibaction)makestory:(id)sender{ nslog(@"makestory:");      makestorytableviewcontroller = [[makestorytableviewcontroller alloc] initwithnibname:@"makestorytableviewcontroller" bundle:nil];     makesentencetableviewcontroller *detailviewcontroller = [[makesentencetableviewcontroller alloc] initwithnibname:@"makesentencetableviewcontroller" bundle:nil];     uisplitviewcontroller *splitviewcontroller = [[[uisplitviewcontroller alloc] init] autorelease];      uinavigationcontroller *rootnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:makestorytableviewcontroller]autorelease];      uinavigationcontroller *detailnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:detailviewcontroller] autorelease];      splitviewcontroller.viewcontrollers = [nsarray arraywithobjects:rootnav, detailnav, nil];     splitviewcontroller.delegate        = makestorytableviewcontroller;      storybotappdelegate *appdelegate = (storybotappdelegate *)[[uiapplication sharedapplication] delegate];     [appdelegate.window setrootviewcontroller:splitviewcontroller]; } 

when try set detailview in uisplitview delegate result of didselectrowatindexpath:, can access navigationcontroller:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {        nslog(@"viewcontrollers: %@", [self.splitviewcontroller viewcontrollers]);     makesentencetableviewcontroller *detailviewcontroller = [[self.splitviewcontroller viewcontrollers] objectatindex:1];     story *storyset = [fetchedresultscontroller objectatindexpath:indexpath];     nslog(@"detailviewcontroller: %@", detailviewcontroller); //logs uinavigationcontroller     [detailviewcontroller setstory:storyset]; //fails here because navigation controllers can't setstory!     [detailviewcontroller refreshtables]; }  

which makes sense, how access tableviews uinavigationcontrollers responsible for? if remove *rootnav , *detailnav , replace them uitableviews in splitviewcontroller.viewcontrollers statement works fine, have no navigation bar:

    makesentencetableviewcontroller *detailviewcontroller = [[makesentencetableviewcontroller alloc] initwithnibname:@"makesentencetableviewcontroller" bundle:nil];     uisplitviewcontroller *splitviewcontroller = [[[uisplitviewcontroller alloc] init] autorelease];      //uinavigationcontroller *rootnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:makestorytableviewcontroller]autorelease];      //uinavigationcontroller *detailnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:detailviewcontroller] autorelease];      splitviewcontroller.viewcontrollers = [nsarray arraywithobjects:makestorytableviewcontroller, detailviewcontroller, nil];     splitviewcontroller.delegate        = makestorytableviewcontroller;      storybotappdelegate *appdelegate = (storybotappdelegate *)[[uiapplication sharedapplication] delegate];     [appdelegate.window setrootviewcontroller:splitviewcontroller]; 

how can access detail tableview controller , keep navigation bar?

here's how figured out. made 2 mistakes, , in mistakes had use uinavigationcontroller.viewcontrollers objectatindex: property.

  1. in function makestory incorrectly assigning uinavigationcontroller delegate instead of makestorytableviewcontroller. fixed doing this, instead (pay special attention splitviewcontroller.delegate section):

    makesentencetableviewcontroller *detailviewcontroller = [[makesentencetableviewcontroller alloc] initwithnibname:@"makesentencetableviewcontroller" bundle:nil];  uisplitviewcontroller *splitviewcontroller = [[[uisplitviewcontroller alloc] init] autorelease];  uinavigationcontroller *rootnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:makestorytableviewcontroller]autorelease];  uinavigationcontroller *detailnav = [[[uinavigationcontroller alloc] initwithrootviewcontroller:detailviewcontroller] autorelease];  splitviewcontroller.viewcontrollers = [nsarray arraywithobjects:rootnav, detailnav, nil];  //splitviewcontroller.viewcontrollers = [nsarray arraywithobjects:makestorytableviewcontroller, detailviewcontroller, nil]; //rootviewcontroller *root = (rootviewcontroller *)[navigationcontroller.viewcontrollers objectatindex:0]  splitviewcontroller.delegate        = [rootnav.viewcontrollers objectatindex:0];  nslog(@"delegate: %@",  [rootnav.viewcontrollers objectatindex:0]);  storybotappdelegate *appdelegate = (storybotappdelegate *)[[uiapplication sharedapplication] delegate]; nslog(@"rootviewcontroller: %@", appdelegate.window);  [appdelegate.window setrootviewcontroller:splitviewcontroller];  nslog(@"appdelegate.window: %@", appdelegate.window.rootviewcontroller); 
  2. i made same mistake again, time in didselectrowatindexpath: , tried setstory in uinavigationcontroller. fix it, did (pay special attention bit navcontrollerdetail.viewcontrollers:

    uinavigationcontroller *navcontrollerdetail; navcontrollerdetail = [[self.splitviewcontroller viewcontrollers] objectatindex:1];    makesentencetableviewcontroller *detailviewcontroller;  detailviewcontroller = [navcontrollerdetail.viewcontrollers objectatindex:0];  story *storyset = [fetchedresultscontroller objectatindexpath:indexpath];    nslog(@"detailviewcontroller: %@", detailviewcontroller); [detailviewcontroller setstory:storyset]; [detailviewcontroller refreshtables]; 

now if figure out how splitviewcontroller rotate properly!


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -