gpt4 book ai didi

iphone - UINavigationController + UITabBar。 viewDidLoad 中的垂直定位错误

转载 作者:行者123 更新时间:2023-12-03 21:16:06 26 4
gpt4 key购买 nike

使用 XCode 4.5 和 iOS6

我创建了一个带有 UITabBar (NIB) 的 UINavigationController,并且第一次启动的选项卡垂直定位不正确。当您单击第二个选项卡并再次单击第一个选项卡时,垂直定位正常。

那么...第一次运行完成后如何正确定位第一个选项卡?

查看错误定位:

http://img231.imageshack.us/img231/2159/badbf.png

我的代码:

AppDelegate.h

@interface bib_AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *mainControllercode;
@property (strong, nonatomic) UITabBarController *tabBarController;

在 AppDelegate.m

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

// change defaul selected icon tabbar color to orange
[[UITabBar appearance] setSelectedImageTintColor:[UIColor orangeColor]];

// Override point for customization after application launch.
UIViewController *viewController1 = [[agendaViewController alloc] initWithNibName:@"agendaViewController" bundle:nil];
UIViewController *viewController2 = [[messagesViewController alloc] initWithNibName:@"messagesViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];

self.mainControllercode = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
self.window.rootViewController = self.mainControllercode;

[self.window makeKeyAndVisible];
return YES;
}

agendaViewController.h

#import <UIKit/UIKit.h>

@interface agendaViewController : UIViewController
@end

agendaViewController.m

#import "agendaViewController.h"

@interface agendaViewController ()

@end

@implementation agendaViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Agenda", @"Agenda");
self.tabBarItem.image = [UIImage imageNamed:@"83-calendar"];
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

编辑1:

我使用您可以看到的 Storyboard创建了一个示例项目。我想在没有 Storyboard的情况下拥有相同的功能,请在此处下载:

http://www.freefilehosting.net/atestsb

谢谢

最佳答案

你的处理方式是错误的。

UITabBarController 应该有 UINavigationController 的集合,然后将其根 Controller 设置为主 Nib。然后,每个选项卡都会处理自己的导航堆栈。

您当前正在将 UITabBarController 放入 UINavigationController 的根目录中。当您在导航堆栈中移动时,这会导致问题并删除选项卡栏。

查看此链接以了解以编程方式处理它的更多详细信息:

http://www.xdracco.net/howto-implement-uinavigationcontroller-uitabbarcontroller-programmatically/

关于iphone - UINavigationController + UITabBar。 viewDidLoad 中的垂直定位错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13177812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com