[iPhone SDK] Interface Builder + View Controllers

Discussion in 'iOS Programming' started by aoberoi, Aug 5, 2008.

  1. aoberoi macrumors newbie

    Oct 30, 2007
    This is going to sound like a newbie question. My programming background is strong but I am very unfamiliar with the managed memory model that Objective-C 2.0 uses with the iPhone. That is where most of my troubles stem from.

    I started reading the section on Navigation Bars in the Interface Builder User Guide (page 61) and I want to do it the way they suggest since it says it will take care of the memory issues of loading and unloading view objects the way its meant to be done.

    I wanted to take the recommended path, so it further gives instructions for doing so.

    What I ended up with was 2 nib files:

    • File's Owner is the UIApplication.
    • The AppDelegate has an outlet called navigationController that is connected to the UINavigationController object below.
    • There is UINavigationController with and its children are a UINavigationBar and my custom view controller class, BuildingsTableViewController. It also has a child (UINavigationItem). The attribute inspector lists "BuildingsTableView" as NIB name.

    • File's Owner is BuildingsTableViewController.
    • At the top level there is also a UITableView object.
    • The File's Owner's view outlet is connected to the UITableView object.

    My XCode project has a BuildingsTableViewController class which subclasses UIViewController but has no additional code other than the template code given when you make a new UIViewController subclass in XCode. The applicationDidFinishLaunching:application implementation looks like this:

    [window addSubview:[navigationController view]];
    // Override point for customization after app launch	
    [window makeKeyAndVisible];
    I get a build error at launch, it looks like this:

    Undefined symbols:
      "_CGRectZero", referenced from:
          _CGRectZero$non_lazy_ptr in BuildingsTableViewController.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    	  "_CGRectZero", referenced from:
    	      _CGRectZero$non_lazy_ptr in BuildingsTableViewController.o
    	ld: symbol(s) not found
    	collect2: ld returned 1 exit status
    Can anyone help me figure out what I am missing? Intuitively, I suspect that I have to instantiate a BuildingTableViewController programmatically somewhere, but I do not know where, and using which method. I am scared of this whole memory managment thing, so a response with detail in that area would be awesome.



    So it was a silly mistake, I was not linking to the CoreGraphics framework in my Xcode project. Oops.

    But there still is a problem. I want to set the BuildingsTableViewController's UINavigationItem inside the BuilidingsTableView.xib. So I attempted to drag and drop one of these into the Document window using the Library at the root level. I then connected File's Owner's navigationItem outlet to this new instance and began setting the name up. Unfortunately, when I run, I still got the UINavigationItem that was set in the MainWindow.xib. Then I tried to remove the UINavigationItem from there, but I couldn't unless I moved the entire BuildingsTableViewController outside of the UINavigationController and in the root level of the Document window. At this point I chose to programatically add the BuildingsTableViewController to the navigationController inside the AppDelegate (using the pushViewController: animate: message). Then, keeping the UINavigationItem the way it was in BuilidingsTableView.xib I tried to run the program. This time i got a blank navigation bar. HOW DO I GET THIS RIGHT?

Share This Page