navigation controller push problem

Discussion in 'iOS Programming' started by flummoxed, Dec 24, 2010.

  1. flummoxed, Dec 24, 2010
    Last edited: Dec 24, 2010

    flummoxed macrumors member

    Joined:
    Nov 27, 2010
    #1
    I'm sure this is a simple thing but I am stumped.

    This is my first attempt at implementing a navController and its not complicated.

    I just want to use a UINavigationController to slide between views.
    Starting with a main app view, press a button, slide to the next view.
    Press a button on this view, slide to the next view.

    I am not using the navigation bar or tool bar, but creating my own nav buttons
    somewhere in the view.

    I created the nav controller in the main.xib nib file and setup the appDelegate.
    I also have the second controller and its view all set up and programmed so I know it all works.

    When I start up the first nav controller view appears with its buttons.
    When I click the button to push to the next view nothing happens.
    Here is the "push" method linked to the button in the main nav controller view. This code is in the navController.m file.

    Code:
    - (void)resumeGame: (id)sender{
    	newViewController *newView = [[newViewController alloc] 
                     initWithNibName:@"newViewController"  bundle:nil];
    	[self  pushViewController:newView	animated:YES];
    	[newView release];
    
    }
    

    When I click the button the code executes because I tested it with a log message. It just does not do anything.
    What am I missing?
     
  2. zachsilvey macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
    #2
    try

    Code:
    [self.navigationController pushViewController:newView animated:YES];
    instead.

    You are sending the pushViewController:animated: message to the navigationController not the view itself so you need to pass it to the view controllers navigationController property.
     
  3. flummoxed, Dec 24, 2010
    Last edited: Dec 25, 2010

    flummoxed thread starter macrumors member

    Joined:
    Nov 27, 2010
    #3
    OK. Thanks a bunch.

    I'm reworking the code to straighten out the main window hierarchy.
    I have a lot of things wrong as well.

    I did not understand the reference to self.navigationController at first because I thought the methods should be directly referenced to the navCntlr itself.

    So now I am programmatically adding the nav controller to the main nib via the AppDelegate.m in -applicationDidFinishLaunching.

    Also creating the rootViewController and its nib , then adding that to the navController in the initWithRootController .

    The control buttons are defined and implemented in the rootViewController.m file.

    Hopefully I did all of this correctly. Thanks.

    I got it working for the push to the 2nd view, but now the problem is, how do I get back to the main view?
    I am not using the built-in navigation bar controls so I have to build the functionality in myself.
    Do I have to create my own delegate for the return trip to the root view?
    It seems there is no other way to reference the top view nav controller since that view is gone.
    How can I reference the nav controller and its methods when I am in a view controller that does not know about its existence?
     
  4. forum user macrumors regular

    Joined:
    Aug 28, 2008
    #4
    In second view add:
    Code:
    - (IBAction)done:(id)sender {
    	[self.navigationController popViewControllerAnimated:YES];
    }
    
    Then in IB for the second view wire a button to connect to the action.
     
  5. flummoxed thread starter macrumors member

    Joined:
    Nov 27, 2010
    #5
    Thanks.

    Finally something turns out easier than I imagined.

    I didn't think the current viewController would be aware of the top Viewcontroller since that was dismissed. I didn't know that "self" would mean the same thing no matter where in the hierarchy the view was.

    I'm glad it is that simple. These simple things take up more of my time than the hard stuff. I can figure out program logic, but this UI stuff can be so elusive. The answers may be simple, but it takes forever to find the answers.
     
  6. forum user macrumors regular

    Joined:
    Aug 28, 2008
    #6
    I agree, the GUI part is taking more time that the program logic part. On the other hand there are more working examples and usable tutorials around for cocoa touch than there are for other languages.
    ...Or maybe the other languages I have to program in are just poorly documented.
     
  7. flummoxed thread starter macrumors member

    Joined:
    Nov 27, 2010
    #7
    It appears that I am finding most of my answers and understanding from other sources such as this forum on the internet, not in Apple's documentation.

    That is unfortunate. Apple's documentation is quite thorough and complete, yet it is muddled in complexity. They fail to reduce the concept down to its most basic form which is the essence of its functionality. They have plenty of program and code examples, but those are complete multi-function programs.
    It is often difficult to extract the core functionality of a single device from a tangled web of other code.

    I just spent nearly 12 hours trying to figure out how to construct a simple window navigation device - much of that time in scouring the Apple docs for answers. Now that I see the true essence of the device I could construct a simple example in less that 30 mins. Why can't they do that?
    Instead they present it in its full complexity and say "see thats how it works".

    I learned how to write UI tools for Maya 3d using their interpreted MEL language. It is similar to C. I learned it from step 1 just reading and using their command docs. The main thing that allowed me to understand it were the simple code examples that they provide at the end of each command document. The code was the most fundamental distillation of that particular command implementation. It could not get any simpler. It was exactly what I needed to see how it worked. I wasted very little time learning to write mel code.
     
  8. zachsilvey macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
    #8
    Apple's documentation isn't for the beginner it's for experienced developers who already know the fundamentals of object oriented programming. Almost everything Apple does is meant to be intuitive and easy to pick up, OOP development is not one of those things. Many people spend 4 years at a university learning this stuff, don't expect to pick it up quickly.

    That being said there are a few resources I found really useful when learning this stuff.
    -Programming in Objective-C 2.0 (book)
    -Beginning iOS Application Development (book)
    -Stanford CS193P (free video lectures from Stanford on iTunes U)
    -Apple's Developer Documentation

    I wouldn't recommend diving straight into the Dev Documentation until you understand concepts like encapsulation and inheritance and you understand the difference between class and instance methods.
     

Share This Page