【问题标题】:Tab bar application with navigation Controller and UIBarButtonitem带有导航控制器和 UIBarButtonitem 的标签栏应用程序
【发布时间】:2015-05-03 19:41:17
【问题描述】:

我创建了一个小型的选项卡式应用程序,并向该选项卡栏添加了 5 个视图控制器。我在该标签栏上添加了一个 NavigationController。我的问题是我无法将 BarButtons 添加到导航栏。我正在使用故事板。

案例一

FirstViewCountroller.m

- (void)viewDidLoad {
    [super viewDidLoad];
   UIBarButtonItem *editBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editAction)];
    self.navigationItem.leftBarButtonItem = editBarButtonItem;
    // Do any additional setup after loading the view, typically from a nib.
}

在这种情况下,我没有得到 bar 按钮,而是得到 tabBar 和 navigationBar

案例 2

我尝试了另一种方式..修改了我的一些代码

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    FirstViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
    UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:ivc];
    self.window.rootViewController =nil;
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

在这种情况下,我得到了 barbutton 和 navigationBar,但没有得到 tabBar。

任何人都可以帮助我。提前致谢

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uitabbarcontroller uinavigationbar


    【解决方案1】:

    您在 AppDelegate.m 中编写的代码不正确。您必须使 TabBarController 成为“InitialViewController”。 最好在情节提要中而不是在代码中进行。 下面是截图。

    首先取一个 UITabBarController 并使其成为初始视图控制器:

    然后取一个 UINavigationController 并将其作为 UITabBarController 的 rootViewController(像这样):

    还有这个:

    为你的 UINavigationController 使用 UIViewController 做同样的事情(像这样):

    还有这个:

    再添加一些后,您将在故事板中得到类似的内容:

    现在您可以根据需要使用任意数量的控制器。

    现在您可以在 UINavigationBar 中添加 UIBarButton。

    希望这会有所帮助。谢谢干杯。

    【讨论】:

    • 谢谢你的回答。像这样,我使用了许多我想添加的 UINavigationcotrollers。但是每个 NavigationBar 都有共同的左右栏按钮,其功能也是相同的..
    • 可以在控制器导航栏的storyboard中手动添加barbuttons,在控制器中制作IBAction并使用该方法。您不必以编程方式执行此操作。
    猜你喜欢
    • 2010-09-27
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2017-05-14
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多