0

I am learning how to create apps with multiple views using the Window-based application template. I am trying to implement a tab bar but when my view loads, it is a blank. I realize it could be an issue between versions of iPhone SDK or Xcode. I am using the latest version of both (iOS 4.3 and Xcode 4.0).

My current code is as follows:

.h file:

@interface iBountyHunterAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabcontroller;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabcontroller;

.m file:

@synthesize window;
@synthesize tabcontroller;
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

// Override point for customization after app launch    
[window addSubview:tabcontroller.view];
[window makeKeyAndVisible];

}

In the sample code I downloaded, this worked fine. I can't figure out where the problem is and any suggestions would be greatly appreciated.

MBguitarburst
  • 267
  • 1
  • 7
  • 21

2 Answers2

1

Have you added any view controllers to the tab bar controller? The tab bar controller doesn't have any content of its own, other than the tab bar itself. You need to add your own view controllers using -setViewControllers:animated:.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I have two custom nav controllers for view controllers. – MBguitarburst Mar 15 '11 at 05:04
  • Again, a navigation controller usually requires another controller to manage. You say 'custom nav controllers', so maybe that's not the case here, but hard to say from what you've posted. In any case, if your tab bar controller isn't showing any content, the most likely cause is a problem in the configuration of the controllers that it manages. – Caleb Mar 15 '11 at 05:10
  • Maybe I need to clarify. My tab bar itself is not showing. The screen itself shows entirely blank white. – MBguitarburst Mar 15 '11 at 06:04
  • Also, I created my tab bar with nibs, and am using two table views with the nav controllers. – MBguitarburst Mar 15 '11 at 06:11
  • Okay, next thing to check is that they're all properly connected. Put a breakpoint in your code above. Is `tabcontroller` pointing to a tab bar controller? Are its view controllers set up? Stuff like that. In other words, you're adding the tab bar controller's view to the window properly, so keep looking. – Caleb Mar 15 '11 at 06:34
  • I did some more tinkering. I am using Xcode 4 and I notice its defaults look a bit different than what my sample code expects. First, the `@interface` of my AppDelegate does not include the `UIWindow *window;`. Second, in my AppDelegate.m, it has `@synthesize window=_window;` – MBguitarburst Mar 17 '11 at 06:46
  • Third, it has '[self.window makeKeyAndVisible];' rather than '[window makeKeyAndVisible];', which I assume is due to the lack of the initial UIWindow in '@interface'. When I add the '[window addSubview:tabcontroller.view];', I was obviously missing some steps. – MBguitarburst Mar 17 '11 at 06:53
1

So I think I figured it out. Due to the lack of the UIWindow *window in the ApplicationDelegate.h @interface:

I had to reference [self.window addSubview:tabcontroller.view]; in my application didFinishLaunching method,

rather than just [window addSubview:tabcontroller.view];

Thanks for the assistance.

MBguitarburst
  • 267
  • 1
  • 7
  • 21
  • You saved my day! Adding self made it work. Don't know why it wasn't working before, cause I did have UIWindow *window in my Delegate.h. Any idea? – Thorben Mar 28 '11 at 12:13