1

在我的应用程序中,我从登录屏幕导航到一个类,比如 classA ,就像这样

classA *objUserHome = [[classA alloc]init];
        [self presentModalViewController:objUserHome animated:YES];
        [objUserHome release];

并且 ClassA 有一个导航栏和一个标签栏(其中有 5 个标签),我已经像这样以编程方式创建了我的标签栏

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Create tab bar controller and navigation bar controller

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *arrControllers = [[NSMutableArray alloc] initWithCapacity:5];

    //Add PunchClock to tab View Controller
    PunchClock* objPunchClock = [[PunchClock alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPunchClock];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPunchClock release];

    //Add Time_Sheet to tab View Controller
    Time_Sheet* objTime_Sheet = [[Time_Sheet alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objTime_Sheet];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objTime_Sheet release];

    //Add PTO to tab View Controller
    PTO* objPTO = [[PTO alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPTO];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPTO release];

    //Add PunchClock to tab View Controller
    CrewPunch* objCrewPunch = [[CrewPunch alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objCrewPunch];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objCrewPunch release];

    //Add PunchClock to tab View Controller
    Reports* objReports = [[Reports alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objReports];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objReports release];

    // Add this view controller array into the tab bar

    //self .viewControllers = arrControllers;
     tabBarController .viewControllers = arrControllers;

    [arrControllers release];
    [self.view addSubview:[tabBarController view]];


}

ClassA is inherited from UIViewController

现在的问题是,在导航到 classA 之后, classA 的视图向下移动了 4 毫米,像这样 为什么会这样?我该如何解决这个问题,请提前帮助我,谢谢

4

4 回答 4

1

在使用情节提要和Modal Transition2 个或更多视图之间时,您可能会遇到与上述类似的错误。

如果您使用Modal Transitionfrom ViewControllerAtoViewControllerZ然后尝试Modal TransitionViewControllerZback toViewControllerA有时视图ViewControllerA会稍微向下推窗口。

可以使用以下方法防止这种情况:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

On从一个事件ViewControllerZ返回ViewControllerAViewControllerZ

于 2012-10-10T12:48:37.347 回答
0

您可能已经在 Interface Builder 或 XIB 文件中选择了一些顶部栏,并另外设置了导航栏。不要选择 XIB 文件中的任何顶部栏。

于 2012-07-09T05:08:04.333 回答
0

尝试如下

[self.navigationController.view addSubview:[tabBarController view]];
于 2012-07-09T05:14:24.273 回答
0

经过长时间的研究,我终于解决了这个问题,只是通过继承类UINavigationController而不是UIViewControler

于 2012-07-09T06:23:00.243 回答