tags:

views:

34

answers:

3

Hi!

I have the following problem: There is a class that includes five tabs in the following way:

mainMenuClient.h

#import <UIKit/UIKit.h>

@interface MainMenuClient : UIViewController {
UITabBarController *tabBarController;
}
@property (nonatomic, retain) UITabBarController *tabBarController;

@end

mainMenuClient.m

-(void)viewDidLoad {

UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];

ContactListTab *contactTab = [[ContactListTab alloc] init];
ChatTab *chat = [[ChatTab alloc]init];
DialerTab *dialer = [[DialerTab alloc]init];
MenuTab *menu = [[MenuTab alloc]init];
TesztingFile *teszting = [[TesztingFile alloc]init];
contactTab.title = @"Contact List";
chat.title = @"Chat";
dialer.title = @"Dialer";
menu.title = @"Menu";
teszting.title = @"TesztTab";

contactTab.tabBarItem.image = [UIImage imageNamed:@"Contacts_icon.png"];
chat.tabBarItem.image = [UIImage imageNamed:@"Chat_icon.png"];
dialer.tabBarItem.image = [UIImage imageNamed:@"Dialer_icon.png"];
menu.tabBarItem.image = [UIImage imageNamed:@"Menu_icon.png"];
teszting.tabBarItem.image = [UIImage imageNamed:@"Contacts_icon.png"];
chat.tabBarItem.badgeValue = @"99";

tabBarController = [[UITabBarController alloc]init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);

[tabBarController setViewControllers:[NSArray arrayWithObjects:contactTab, chat, dialer, menu, teszting, nil]];

[contactTab release];
[chat release];
[dialer release];
[menu release];
[teszting release];

[self.view addSubview:tabBarController.view];

[super viewDidLoad];
}

In the contactTab class there are a UITableViewController.

contactTab.h

- (void)updateCellData;
- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath;

There is a third class, which I would like to achieve is a method of UITableViewController's (from ContactTab).

So far I tried this: When I tried to achieve the UItabbarController:

MainMenuClient *menu;
UITabBarController *tabBarControllerchange = [[UITabBarController alloc] init];
tabBarControllerchange = menu.tabBarController;
[tabBarControllerchange setSelectedIndex:0];

When I tried to achieve the UITableViewController:

ContactListTab *contactListTab;
[contactListTab updateCellData];

Does anybody have an idea for this problem? Thanks. Balazs.

A: 

You need to get the instance of your MainMenuClient:

define method in your MainMenuClient.h as:

+(MainMenuClient*)getMainMenuInstance;

Implement the following method in MainMenuClient.m as :

+(MainMenuClient*)getMainMenuInstance
{
     return self;
}

Now you can get same instance of UITabBarContrtoller in any class as :

MainMenuClient *menuClient = [MainMenuClient getMainMenuInstance];
UITabBarContrtoller *newTabBarController = menuClient.tabBarController;

You can do what ever you want to do with this new UITabBarController object.

Hope this helps.

Jim.

Jim
I try it, but I get the following error to the second row:+[MainMenuClient tabBarController]: unrecognized selector sent to class 0x12bd00Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[MainMenuClient tabBarController]: unrecognized selector sent to class 0x12bd00'
BaluEdo
A: 

Hi again!

So, there is two classes, one of which is included the UITabBarController. Linked to this is second class that also includes the UItableViewController. These are normally run.

When I try to achieve UITabBarController form a third class, that change the selected tab. And in this third class I like to use a UITableView method (ContactListTab), but when I run the program, it will crash.

That would be my question, what's the problem? Because I want this class was to switch tabs without interfering with the user, and the Table View, more like a method of manipulating.

BaluEdo
A: 

I try it, but I get the following error to the second row:

+[MainMenuClient tabBarController]: unrecognized selector sent to class 0x12bd00

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[MainMenuClient tabBarController]: unrecognized selector sent to class 0x12bd00'

BaluEdo