objective c - Not understanding how the NavigationController and UIViewControllers are working in iOS -


i have project don't understand views , navigation behind. start out in appdelegate (maappdelegate), define properties:

@property (strong, nonatomic) uiwindow *window; @property (strong, nonatomic) uiviewcontroller *detailviewcontroller; 

then in maappdelegate.m, create navigationcontroller, ,

@implementation maappdelegate @synthesize detailviewcontroller; @synthesize window;  - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];      // init navcontroller master detail view of grade cells      uinavigationcontroller *navcontroller = [[uinavigationcontroller alloc] init];       detailviewcontroller = [[uiviewcontroller alloc] init];      uiviewcontroller *viewcontroller = [[macontroller alloc] init];      navcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller];      self.window.rootviewcontroller = viewcontroller;      [self.window makekeyandvisible];      return yes; } 

so @ point, think have working naviationcontroller, i've setup instance of custom uiviewcontroller (custom class macontroller) , i've set rootviewcontroller.

then, in macontroller class, class all of ui stuff (the entire ui done programmatically, no nibs or storyboards). here bit of viewdidload of macontroller:

- (void)viewdidload {     [super viewdidload];     // additional setup after loading view.       [self.navigationcontroller setnavigationbarhidden:yes]; // commented line out , realized nothing 

i go on (in viewdidload) add bunch of subviews self.view,

[self.view addsubview:self.backgroundimageview]; 

earlier, created viewcontroller in appdelegate class , called view, assumed refereeing since i've changed (in appdelegate) viewcontroller, guess thinking wrong?

and finally, create uiview in 'viewdidload`:

uiview *header = [[uiview alloc] initwithframe:headerframe]; header.backgroundcolor = [uicolor clearcolor]; self.tableview.tableheaderview = header; 

and start adding bunch of subviews new uiview created header.

so, in short, have no idea happening. later, when tried telling (from method inside macontroller) self.navigationcontroller (which assumed navigationcontroller in charge of in project - created @ beginning in appdelegate) pushviewcontroller new viewcontroller going use detailview table, got weird.

so i'm trying understand has control, , rootviewcontroller is, , happening.

the main window root set view controller , not navigation controller

change:

self.window.rootviewcontroller = viewcontroller; 

to:

self.window.rootviewcontroller = navcontroller; 

edit:

you can access navigationcontroller anywhere asking appdelegate. not considered practice:

maappdelegate *delegate = (maappdelegate *)[[uiapplication sharedapplication] delegate]; uinavigationcontroller *nav = delegate.navigationcontroller; 

don't forget to:

#import "maappdelegate.h" 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -