UITabBarContrtoller achieve from a different class in iPhone
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 开发者_Go百科= @"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.
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.
精彩评论