tags:

views:

34

answers:

3

my app is based on tabbar controller now in my default view i am showing a viewController and lets say it has Button A, when user press A it should load a my tableviewController but nothing is happening??

-(IBAction)promo:(id)sender
{
  aRoot= [[tableViewController alloc] initWithNibName:@"tableViewController" bundle:[NSBundle mainBundle]];
  [self.navigationController pushViewController:aRoot animated:YES];

}

but its not loading anything no error even???

/////////// UPDATE

i did this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    





 Promo *aPromo = [[Promo alloc] initWithNibName:nil bundle:nil];//button A is deifned on this VC
 // then...
 aNav = [[UINavigationController alloc] initWithRootViewController:aPromo];
// [pageOne release];

and in promoviewController

-(IBAction)promo:(id)sender
{atab= [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];

 //TableViewController *atab1 = [[TableViewController alloc]initWithNibName:@"TableViewController" bundle:[NSBundle mainBundle]];


 [self.navigationController pushViewController:atab animated:YES];



}
A: 

you can't add a viewcontroller to a uitabbar if you want to use the navigation controller.

Where you make your tab bar controller you have to do this:

MyFirstTabViewController *pageOne = [[MyFirstTabeViewController alloc] initWithNibName:nil bundle:nil];
// then...
UINavigationController *ncOne = [[UINavigationController alloc] initWithRootViewController:pageOne];
[pageOne release];

then add ncOne to the tab bar instead of the view controller. :) Then your code in the question should work (given that you're properly declaring aRoot in the header).

EDIT Start again... choose a view based application call it TabBarTest.

Right click on classes and add three new classes. They need to be subclasses of UIViewController or UITableViewController. Lets say they're called RootViewOne RootViewTwo and SecondaryViewController.

Then open TabBarTestViewController.m

Uncomment the viewDidLoad method.

You need to now put this code in that method:

UITabBarController *tbc = [[UITabBarController alloc] init];

NSMutableArray *viewControllers = [NSMutableArray array];

RootViewOne *vc1 = [[RootViewOne alloc] initWithNibName:nil bundle:nil];
UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
nc1.view.backgroundColor = [UIColor redColor];
[viewControllers addObject:nc1];
[vc1 release];

RootViewTwo *vc2 = [[RootViewTwo alloc] initWithNibName:nil bundle:nil];
UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
nc2.view.backgroundColor = [UIColor blueColor];
[viewControllers addObject:nc2];
[vc2 release];

[tbc setViewControllers:viewControllers animated:YES];

[self presentModalViewController:tbc animated:YES];

Now open RootViewOne.m and in viewDidLoad put this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Click to move through stack" forState:UIControlStateNormal];
[button addTarget:self action:@selector(moveToNextView:) forEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

Now you're going to need a custom method:

-(void)moveToNextView:(id)selector {
  SecondaryViewController *page = [[SecondaryViewController alloc] initWithNibName:nil bundle:nil];
  page.title = @"Next Page";
  page.view.backgroundColor = [UIColor greenColor];
  [self.navigationController pushViewController:page animated:YES];
  [page release];
}

This is only basic, but you should get an understanding of the kinad process you need to go through. I typed this straight into the browser so there may be spelling mistakes... watch out if you get any errors or warnings. Hopefully this can help you with your project.

Thomas Clayson
where should i put this code ?? in appdidfinsihlaunch??
prajakta
i did this - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { Promo *aPromo = [[Promo alloc] initWithNibName:nil bundle:nil]; // then... aNav = [[UINavigationController alloc] initWithRootViewController:aPromo];// [pageOne release];
prajakta
erm, thats not right.... are you using IB? I don't use IB unfortunately, my solution is programatic.
Thomas Clayson
its ok i changed to Programmatic , but what should i write in IBAction()??
prajakta
see my edit.....
Thomas Clayson
thanks but its not working for me .. just to load a new view on button tap its difficult to change whole architecture of my project , :( , i tried your way also but its not loading my tableview... hey when i tried this [self presentModalViewController:atab animated:YES]; then can load new window but that hides all my tabbar icons , if i can unhide those then i think my work will be safe :( plz suggest any other method if you have thanks
prajakta
i did it whowwww..... i made that as navigation controller instead of VC thanks
prajakta
A: 

Finally i solved this , i changed that VC to Navigation view Controller and then i can push the new view based on button tap,, thanks to thomas also who helped me a lot but i couldn't figure it out.

prajakta
A: 

You need a navigationController to push a viewController.

AWright4911