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??
我的应用程序基于tabbar控制器现在在我的默认视图中我显示一个viewController并让我们说它有按钮A,当用户按A它应该加载我的tableviewController但没有发生什么?
-(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
并在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];
}
3 个解决方案
#1
0
You need a navigationController to push a viewController.
你需要一个navigationController来推送一个viewController。
#2
0
you can't add a viewcontroller to a uitabbar if you want to use the navigation controller.
如果要使用导航控制器,则无法将视图控制器添加到uitabbar。
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).
然后将ncOne添加到选项卡栏而不是视图控制器。 :)然后你的问题中的代码应该工作(假设你正确地在标题中声明了一个Root)。
EDIT Start again... choose a view based application
call it TabBarTest
.
编辑再次开始...选择一个基于视图的应用程序调用它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
.
右键单击类并添加三个新类。它们需要是UIViewController或UITableViewController的子类。让我们说它们被称为RootViewOne RootViewTwo和SecondaryViewController。
Then open TabBarTestViewController.m
然后打开TabBarTestViewController.m
Uncomment the viewDidLoad
method.
取消注释viewDidLoad方法。
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:
现在打开RootViewOne.m并在viewDidLoad中输入:
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.
这只是基本的,但您应该了解您需要经历的kinad过程。我直接在浏览器中键入了这个,因此可能会出现拼写错误...请注意是否有任何错误或警告。希望这可以帮助您完成项目。
#3
0
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.
最后我解决了这个问题,我将VC更改为导航视图控制器,然后我可以根据按钮点击推送新视图,感谢托马斯也帮助了我很多,但我无法弄明白。
#1
0
You need a navigationController to push a viewController.
你需要一个navigationController来推送一个viewController。
#2
0
you can't add a viewcontroller to a uitabbar if you want to use the navigation controller.
如果要使用导航控制器,则无法将视图控制器添加到uitabbar。
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).
然后将ncOne添加到选项卡栏而不是视图控制器。 :)然后你的问题中的代码应该工作(假设你正确地在标题中声明了一个Root)。
EDIT Start again... choose a view based application
call it TabBarTest
.
编辑再次开始...选择一个基于视图的应用程序调用它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
.
右键单击类并添加三个新类。它们需要是UIViewController或UITableViewController的子类。让我们说它们被称为RootViewOne RootViewTwo和SecondaryViewController。
Then open TabBarTestViewController.m
然后打开TabBarTestViewController.m
Uncomment the viewDidLoad
method.
取消注释viewDidLoad方法。
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:
现在打开RootViewOne.m并在viewDidLoad中输入:
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.
这只是基本的,但您应该了解您需要经历的kinad过程。我直接在浏览器中键入了这个,因此可能会出现拼写错误...请注意是否有任何错误或警告。希望这可以帮助您完成项目。
#3
0
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.
最后我解决了这个问题,我将VC更改为导航视图控制器,然后我可以根据按钮点击推送新视图,感谢托马斯也帮助了我很多,但我无法弄明白。