Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hassoon

macrumors regular
Original poster
Jun 8, 2009
154
0
hi, i was working with a project using the Empty Template and now i want to implement a navigation controller. first i dropped a navigation controller from the objects library but when running the app, the app doesn't view what i wanted to be views such as buttons, UImages,...etc. i feel like that i must add something in the appDelegate files but i actually don't know. Besides, ya i know i can use the master-detail template but being a developer i wanna know the basics and what's happening behind the scenes in each template. Thank you!
 
When you use the Empty Application template, you must set a UIViewController or, normally, a subclass of it as your window's rootViewController in the appDelegate. UINavigationController is a subclass of UIViewController.
 
When you use the Empty Application template, you must set a UIViewController or, normally, a subclass of it as your window's rootViewController in the appDelegate. UINavigationController is a subclass of UIViewController.

i wrote the following in the application:didFinishLunchingWithOptions:
Code:
SSPHomeScreenViewController *myViewController = [[SSPHomeScreenViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
    self.window.rootViewController = navigationController;

and it's still not working.
 
Not working how? Please elaborate. What were you expecting to happen and what happened instead? Did you get any warnings/errors/crashes? Etc.

i mean that the simulator is showing a blank white page. i'm expecting to show me a navigation controller base view with a bar (besides the buttons that i added). To best understand my problem just create a an empty project in xcode and once created add a navigation controller object from the library and run the app. an error will tell you that the application window is expecting a view controller. so i'm sure that there's something to add in order to hook the navigation controller to the root controller but i don't know what it is. Thank you so much for the help you're giving me.
 
To best understand my problem just create a an empty project in xcode and once created add a navigation controller object from the library and run the app.

From the library? What library? Add the navigation controller object to what? All you have at this point is a AppDelegate class. Maybe you should provide some screenshots or better details of what exactly you are doing in order for us to better understand.
 
From the library? What library? Add the navigation controller object to what? All you have at this point is a AppDelegate class. Maybe you should provide some screenshots or better details of what exactly you are doing in order for us to better understand.

oh, i mean the object library to the right under the inspector. and add the navigation controller to the storyboard. anyway, here are the screenshots and a briefer explanation.
I created a project on xcode with an Empty project template. i added a navigation controller object from the object library to the story board. i ran the app and a white blank view appeared only. i was expecting a view with a top bar for navigation (at least). besides an error occurred that the application window is expecting a root controller. Problem: i don't know how to hook up the navigation controller object in the storyboard to the app root controller so that when i run the app the navigation controller and bar will appear. the attached pictures shows my set up (didn't add any code yet).
 

Attachments

  • Screen Shot 2013-02-26 at 9.55.04 PM.png
    Screen Shot 2013-02-26 at 9.55.04 PM.png
    243.4 KB · Views: 129
  • Screen Shot 2013-02-26 at 9.56.58 PM.png
    Screen Shot 2013-02-26 at 9.56.58 PM.png
    82.3 KB · Views: 108
I created a project on xcode with an Empty project template.

Do you mean the Empty Application template? As seen in the screenshot below? If so, that doesn't come with any storyboards, so I'm confused.
 

Attachments

  • Screen Shot 2013-02-26 at 1.12.03 PM.png
    Screen Shot 2013-02-26 at 1.12.03 PM.png
    204.1 KB · Views: 125
  • Screen Shot 2013-02-26 at 1.12.14 PM.png
    Screen Shot 2013-02-26 at 1.12.14 PM.png
    216.4 KB · Views: 128
Do you mean the Empty Application template? As seen in the screenshot below? If so, that doesn't come with any storyboards, so I'm confused.

ya exactly, i know it doesn't but you can add one.
 
ya exactly, i know it doesn't but you can add one.

Well, that's kind of an important step that you failed to mention previously. Anyways, just because you add a storyboard to an Empty Application template does not mean the application will use it. You would still need to set it as the main storyboard for your target.
 
Well, that's kind of an important step that you failed to mention previously. Anyways, just because you add a storyboard to an Empty Application template does not mean the application will use it. You would still need to set it as the main storyboard for your target.

I did and the problem persist.. Did it work to you?
 
It did. But I removed some code from application:didFinishLaunchingWithOptions:. Can you guess what?

i tried deleting with all the possible combinations and it's not working. did you add anything beside deleting ?
 
i tried deleting with all the possible combinations and it's not working. did you add anything beside deleting ?

Nope. Only deleted code. Think about what happens when you set the Main Storyboard for your target and how that might conflict with the template code that resides in application:didFinishLaunchingWithOptions:.
 
Nope. Only deleted code. Think about what happens when you set the Main Storyboard for your target and how that might conflict with the template code that resides in application:didFinishLaunchingWithOptions:.

mmm... sounds like a riddle. can i take a look of the template code or the automatic code that is generated for any template chosen?
 
Why not just create a stub-project using the template you're curious about?

I have two reasons why I don't want to use another template:
1. I want learn the basics of navigation controllers.
2. If I choose single view template I will not be able to use core data (automatic implementation) since I'm a Beginner. However I can choose a master-detail template and then create my own classes and stuff but I will also face the obstacle of implementing core data methods and stuff.

If you're willing to help me please do, it seems you got the answer.
 
I have two reasons why I don't want to use another template:
Perhaps you misunderstood. (Or I'm confused.) You asked "can i take a look of the template code or the automatic code that is generated for any template chosen?" I gave you a way: create a stub-project based on that template. Before you change anything, look at the code it created.

Anyways, back to the Empty Application project. Initially, it should contain the following:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
Then read what the View Controller Programming Guide says happens if you define a main storyboard for your project. How does the code from the template method conflict with what iOS is doing in regards to the main storyboard?

If you're willing to help me please do, it seems you got the answer.
I am willing to help, but I'm not just going to give you the solution. I find that if I discover the answer through my own problem-solving (and perhaps a few hints), then that "eureka" moment causes me to better recall the solution later on than if someone else just gave me the code. So that's how I try to help others, as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.