如果我直接指出问题,那么我的问题是我有一个带两个按钮的UIViewController。


第一个按钮-(onclick必须导航到)--> UITabbarController带有4个UITabbar项,否则我可以在新的UITabbar中使用一个UIViewController
按钮二-(OnClick必须导航到)--> UITabbarController其中第一个tabbaritem将包含UITableView,或者我可以在我的新UITabbar中使用一个UIViewController,其中第一个TabbarItem将包含UITableView


我该怎么做???样例代码对建议都没有帮助。如果您需要任何澄清,请随时询问。

最诚挚的问候
埃蒙

最佳答案

首先,如果要在单击按钮时按下另一个视图控制器,则需要有一个NavigationController。您需要执行的步骤如下


从iPhone上的MasterDetail应用开始
在xib文件中,放置您的按钮并将其连接到正确的方法
在视图确实出现的视图控制器中有以下代码

self.tbc1 = [[UITabBarController alloc] init];
self.tbc2 = [[UITabBarController alloc] init];


UIViewController *tbc1vc1 = [[UIViewController alloc] init];
UIViewController *tbc1vc2 = [[UIViewController alloc] init];
UIViewController *tbc1vc3 = [[UIViewController alloc] init];

UITableViewController *tbc2vc1 = [[UITableViewController alloc] init];
UIViewController *tbc2vc2 = [[UIViewController alloc] init];
UIViewController *tbc2vc3 = [[UIViewController alloc] init];

[self.tbc1 setViewControllers:[NSArray arrayWithObjects:tbc1vc1,tbc1vc2,tbc1vc3, nil]];
[self.tbc1 setViewControllers:[NSArray arrayWithObjects:tbc2vc1,tbc2vc2,tbc2vc3, nil]];

当然,您必须在视图控制器中为tbc1和tbc2定义属性。
在应用程序委托中,执行以下操作

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

ViewController *myViewController = [[ViewController alloc] init];
self.viewController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

将.h文件中的UIViewController更改为UINavigationController,例如

@property (strong, nonatomic) UINavigationController *viewController;

有两个按钮并将其连接到以下方法

-(IBAction)tbc1Clicked{
[self.navigationController pushViewController:self.tbc1 animated:YES];
}

-(IBAction)tbc2Clicked{
    [self.navigationController pushViewController:self.tbc2 animated:YES];
}

关于iphone - 如何在ViewController中使用UITabbar?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13828681/

10-12 14:39