2012-06-07 3 views
1

J'ai besoin de définir une action pour mon UITabbar, Comme lorsque je clique sur mon tabbar, il devrait aller à une action que j'ai dans un autre viewcontroller.Impossible de définir l'action pour UITabbarItem par programme

mais redirigeant vers UITableview

ici est mon code -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

// create our table view controller that will display our store list  
FirstViewController *firstViewController = [[EzMasterViewController alloc] init]; 


// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
[navController.tabBarItem setTitle:@"Home"]; 
[navController.tabBarItem setImage:[UIImage imageNamed:@"53-house.png"]]; 


SecondViewController *secondViewController = [[SecondViewController alloc] init]; 


// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller 
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
[navController1.tabBarItem setTitle:@"Scan"]; 
[navController1.tabBarItem setImage:[UIImage imageNamed:@"195-barcode.png"]]; 

ThirdViewController *thirdViewController = [[ThirdViewController alloc] init]; 


// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller 
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:thirdViewController]; 
[navController2.tabBarItem setTitle:@"Map"]; 
[navController2.tabBarItem setImage:[UIImage imageNamed:@"07-map-marker.png"]]; 

// add our view controllers to an array, which will retain them 
NSArray *viewControllers = [NSArray arrayWithObjects:navController, navController1,navController2, nil]; 

// add our array of controllers to the tab bar controller 
UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
[tabBarController setViewControllers:viewControllers]; 

// set the tab bar controller as our root view controller  
[self.window setRootViewController:tabBarController]; 

// Override point for customization after application launch. 
[self.window makeKeyAndVisible]; 
return YES; 

}

En cliquant sur SecondViewController tabbaritem il devrait rediriger vers l'action, où l'action est en FirstViewController .

Répondre

0

Vous devriez envisager d'appliquer les UITabBarControllerDelegate's deux méthodes:

– tabBarController:shouldSelectViewController: 
– tabBarController:didSelectViewController: 
+0

salut, u peut me donner un détails plz, en FirstViewController j'ai un buttonaction je veux appeler un à appdelegate, –

Questions connexes