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

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,567
6,073
OK, I want my game to pause if the player selects one of the other tabs.

Here's the code I tried...

first off, I made outlets for all the tabs and the tab bar those have all been connected in Interface Builder.
Code:
	IBOutlet	UITabBar		*tabBar;
	IBOutlet	UITabBarItem		*optionsTab;
	IBOutlet	UITabBarItem		*numbersTab;
	IBOutlet	UITabBarItem		*scoresTab;
	IBOutlet	UITabBarItem		*instructionsTab;

I've got this to set my controller object as the delegate of all the tabs:
Code:
- (void) awakeFromNib
{
	tabBar.delegate = self;
	optionsTab.delegate = self;
	numbersTab.delegate = self;
	scoresTab.delegate = self;
	instructionsTab.delegate = self;
}

There's an error for each one of the tab items...
error: request for member 'delegate' in something not a structure or union

I have tried commenting them out, and the compiler will run without errors, but it still doesn't work.

I also have:

Code:
@interface Controller : NSObject <UITextFieldDelegate, [b]UITabBarDelegate[/b]>

In my header so that I wouldn't get the compiler error that I was missing the protocols.

And finally I have this:
Code:
- (void) tabBar: tabBar didSelectItem: tabItem
{
	NSLog(@"Recognises that a tab item was selected.");
	[self pauseGame];
}
I get the following warning here:
warning: conflicting types for '-(void)tabBar: (id)tabBar didSelectItem: (id)tabItem'

The NSLog message isn't ever posted meaning something prior to the code for pauseGame isn't working.
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
UITabBarItems do not have delegates. Look at the documentation for UITabBar and UITabBarDelegate. Your delegate method is not defined correctly.
 

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,567
6,073
...

OK...

I got rid of the outlets and the messages to set the delegates of the tab items (but not the tab bar.)

I changed other bit to:

Code:
- (void) tabBar: (UITabBar *) tabBar didSelectItem: (UITabBarItem *) item
{
	NSLog(@"Recognizes that a tab item was selected.");
	[self pauseGame];
}

which got rid of the warning message.

But it still doesn't work. The NSLog message is never sent.

I also tried:

Code:
- (void) tabBar: (UITabBar *) tabBar didSelectItem: (UITabBarItem *) optionsTab
{
	NSLog(@"Recognizes that a tab item was selected.");
	[self pauseGame];
}

with the optionsTab outlet set up again, but it still didn't work.

Edit: OK, I found out what I actually needed was the TabBarControllerDelegate's

- (void) tabBarController: (UITabBarController *) tabBarController didSelectViewController: (UIViewController *) viewController

method.

Now it all works properly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.