Hello!
A friend gave me a small tutorial to iPhone programming yesterday. I then tried to make a small program with two views which I can switch using a TabBar: One with a blue background, one with a red one.
It displays them just fine, but when I run it (in the Simulator) and click on a Tab, it crashed with :
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMachPort _tabBarItemClicked:]: unrecognized selector sent to instance 0x38223e0"
I didn't manage to find the bug so far... Have you got any ideas ? :)
Code from DemoAppDelegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
UIColor *color = [UIColor blueColor];
DemoAppViewController *controller1 = [[DemoAppViewController alloc] initWithColor:color];
color = [UIColor redColor];
DemoAppViewController *controller2 = [[DemoAppViewController alloc] initWithColor:color];
[controller1 updateBackground];
[controller2 updateBackground];
UITabBarController *tbcontroller = [[UITabBarController alloc] init];
NSMutableArray *array = [NSMutableArray arrayWithObjects: controller1, controller2, nil];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Blue" image:nil tag:1];
[controller1 setTabBarItem: item];
[item release];
item = [[UITabBarItem alloc] initWithTitle:@"Red" image:nil tag:2];
[controller2 setTabBarItem: item];
[item release];
[tbcontroller setViewControllers:array];
[tbcontroller setSelectedIndex:0];
[window addSubview: [tbcontroller view]];
[tbcontroller release];
[controller1 release];
[controller2 release];
}
Code excerpt from DemoAppViewController:
- (DemoAppViewController *) initWithColor:(UIColor *)color
{
self = [super init];
if (self != nil) {
[color retain];
backgroundColor = color;
}
return self;
}
- (void) updateBackground
{
UIView *view = [self view];
[view setBackgroundColor: backgroundColor];
}