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

alexpja

macrumors member
Original poster
Mar 22, 2010
81
0
Hi, I'd like to know how I can make a third tab exactly like the first and second tabs pictured here:

upoloadme.png


In XCode, the tab bar appears blank, so no clue what to do. I used a preset when making a new project.

Thanks!
 

vultureboy

macrumors member
Nov 28, 2006
62
0
Blackpool, UK
You need to Create a new ViewController for your third tab. In the new view controller "initWithNibName" method, add your details.

Code:
if (self) {
    self.title = @"New Tab";
    self.tabBarItem.image = [UIImage imageNamed:@"imagename"];
}

Now go to your AppDelegate file, import your new view controller at the top of the file. In the "didFinishLaunchingWithOptions" method you should see something like the following...

Code:
UIViewController *viewController1, *viewController2;

viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

You would change this to something like the following

Code:
UIViewController *viewController1, *viewController2, *newViewController;

viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController_iPhone" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, newViewController, nil];

And that should then show a third tab.

If none of that made any sense to you then you need to read up on (at least) some very basic tutorials before you continue. However, I hope it was of some use! :)
 

alexpja

macrumors member
Original poster
Mar 22, 2010
81
0
Works amazingly!

New problem though, my app stopped showing my viewControllers. I have Googled a lot on why it would do that and cannot find my solution :( It told me:

'Applications are expected to have a root view controller at the end of application launch'

I found a solution, but now it stops at breakpoint 3:

Code:
#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

That is main.m, and it stops at main.m:15 which is @authreleasepool {.

Help? :(
 

alexpja

macrumors member
Original poster
Mar 22, 2010
81
0
After disabling breakpoints, I get this:

Code:
CloverCloudPrototype[79044:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x685bc60> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
(0x13bc052 0x154dd0a 0x13bbf11 0x9b3032 0x924f7b 0x924eeb 0x93fd60 0x23291a 0x13bde1a 0x1327821 0x23146e 0x233010 0x1314a 0x13461 0x127c0 0x21743 0x221f8 0x15aa9 0x12a6fa9 0x13901c5 0x12f5022 0x12f390a 0x12f2db4 0x12f2ccb 0x122a7 0x13a9b 0x26e8 0x2645)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb)

and main.m shows line 16:

Code:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

as 'Thread 1: Program received signal: "SIGABRT".'

Have no clue why it would do this :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.