UITabBar的导航栏在视图以模态方式呈现时隐藏导航栏

发布于 2024-10-08 18:37:08 字数 1995 浏览 4 评论 0原文

我有带有 UItabBarTemplate 和导航控制器的应用程序。
在选择选项卡栏时,会显示 ViewControllerA,在按钮触摸时会推动继承“UIViewController”的 UIPieChartTabController。
现在我想要在 UIPieChartTabController 中另一个选项卡栏。
所以在 UIPieChartTabController 的 viewDidLoad 中,

- (void)viewDidLoad {
    [super viewDidLoad];

     UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
     contentView.backgroundColor = [UIColor whiteColor];
     self.view = contentView;
     [contentView release];
      UITabBarController *tabbar= [[UITabBarController alloc] init];
     tabbar.view.frame = CGRectMake(0, 0, 320, 460);
    piechartViewController *pr=[[piechartViewController alloc]init];
    pr.tagInAction=1;
    pr.title=@"Type";
    pr.tabBarItem.image=[UIImage imageNamed:@"trend.png"];
    pr.sDate=sDate;
    pr.nDate=nDate;

    piechartViewController *pr1=[[piechartViewController alloc]init];
    pr1.title=@"category";
    pr1.tagInAction=4;
    pr1.sDate=sDate;
    pr1.nDate=nDate;

    piechartViewController *pr2=[[piechartViewController alloc]init];
    pr2.title=@"paidWith";
    pr2.tagInAction=3;
    pr2.sDate=sDate;
    pr2.nDate=nDate;

    //tabbar.tabBar.delegate=self;
//this gave me error

    ExportRep *pr3=[[ExportRep alloc]init];
    pr3.tabBarItem.image=[UIImage imageNamed:@"database.png"];
    pr3.title=@"Export Expenses";

    [tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
    [self.view addSubview:tabbar.view];
    [pr release];
    [pr1 release];
    [pr2 release];
}

这段代码有效,但是现在当我选择 viewController ExportRep 类型的选项卡时,我尝试了

[self presentModalViewController:objMFMailComposeViewController animated:YES];

,但 objMFMailComposeViewController 的 navigationController 隐藏在呈现 objMFMailComposeViewController 的视图的 navigationController 后面。

此外,绑定到选项卡栏的所有视图控制器的 viewWillAppear viewDidAppear 永远不会被调用。

但对于由 UITabbarTemplate 创建的选项卡栏和视图控制器,不会出现此问题。
为什么会这样呢?我创建标签栏时出了什么问题?

I have app with UItabBarTemplate with navigation controller.
On selecting tab bar ViewControllerA is shown which on button touch pushes UIPieChartTabController which inherits "UIViewController".
Now I want another tab bar in UIPieChartTabController.
so in viewDidLoad of UIPieChartTabController

- (void)viewDidLoad {
    [super viewDidLoad];

     UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
     contentView.backgroundColor = [UIColor whiteColor];
     self.view = contentView;
     [contentView release];
      UITabBarController *tabbar= [[UITabBarController alloc] init];
     tabbar.view.frame = CGRectMake(0, 0, 320, 460);
    piechartViewController *pr=[[piechartViewController alloc]init];
    pr.tagInAction=1;
    pr.title=@"Type";
    pr.tabBarItem.image=[UIImage imageNamed:@"trend.png"];
    pr.sDate=sDate;
    pr.nDate=nDate;

    piechartViewController *pr1=[[piechartViewController alloc]init];
    pr1.title=@"category";
    pr1.tagInAction=4;
    pr1.sDate=sDate;
    pr1.nDate=nDate;

    piechartViewController *pr2=[[piechartViewController alloc]init];
    pr2.title=@"paidWith";
    pr2.tagInAction=3;
    pr2.sDate=sDate;
    pr2.nDate=nDate;

    //tabbar.tabBar.delegate=self;
//this gave me error

    ExportRep *pr3=[[ExportRep alloc]init];
    pr3.tabBarItem.image=[UIImage imageNamed:@"database.png"];
    pr3.title=@"Export Expenses";

    [tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
    [self.view addSubview:tabbar.view];
    [pr release];
    [pr1 release];
    [pr2 release];
}

This piece of code worked but now when I select tab of viewController ExportRep type I tried

[self presentModalViewController:objMFMailComposeViewController animated:YES];

but navigationController of objMFMailComposeViewController hides behind navigationController of view that is presenting objMFMailComposeViewController.

Also viewWillAppear viewDidAppear of all the view controller which are bound to tab bar never gets called.

But none of this problem occurs for tabbar and viewcontroller which gets created by UITabbarTemplate.
Why Is it so? Whats wrong when I create Tab bar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剪不断理还乱 2024-10-15 18:37:08

不建议在 tabbarVC 中放置另一个 tabBar。为什么不使用 UIToolBar 来交换 PieChartVC 中的视图呢?

- 除此之外,您的代码不调用 viewWillAppear、viewDidAppear 的原因是这样的:

[tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
[self.view addSubview:tabbar.view];

这里只会调用这些 prs 的 loadView 。

您分配给 tabBar 的 viewController 应该包裹在 UINavigationController 周围。

所以像这样的东西就可以解决问题

UINavigationController *nc1 = [[UINavigationController alloc]initWithRootViewController:pr];
[nc1.view setFrame:CGRectMake:("the frame in which you wnt prs to be displayed")];
[pr.view setFrame:nc1.view.frame];
. // similarly assign NavControllers for all prs
.
.
.
[tabbar setViewControllers:[NSArray arrayWithObjects:nc,nc1,nc2,nc3,nil]];
    [self.view addSubview:tabbar.view];

placing another tabBar within a tabbarVC, is not recommended. Why not use a UIToolBar to do the swapping of Views in your PieChartVC instead?

-apart from that, the reason your code doesn't call viewWillAppear,viewDidAppear is because of this:

[tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,pr3,nil]];
[self.view addSubview:tabbar.view];

here only loadView of those prs will be called.

the viewControllers you assign to the tabBars should instead be wrapped around UINavigationControllers.

So something like this instead would do the trick

UINavigationController *nc1 = [[UINavigationController alloc]initWithRootViewController:pr];
[nc1.view setFrame:CGRectMake:("the frame in which you wnt prs to be displayed")];
[pr.view setFrame:nc1.view.frame];
. // similarly assign NavControllers for all prs
.
.
.
[tabbar setViewControllers:[NSArray arrayWithObjects:nc,nc1,nc2,nc3,nil]];
    [self.view addSubview:tabbar.view];
花之痕靓丽 2024-10-15 18:37:08

模态呈现的新视图隐藏其导航栏的原因在于 [self.view addSubview:tabbar.view];
因此它有空间仅在父控制器视图中呈现其视图,因此其导航栏被剪切。
因此,为了破解它,我选择了选项卡,而不是在选定的视图控制器中呈现它,而是仅在主视图控制器中呈现它。

The reason why new view which is being presented modally got its navigation bar hidden lies in [self.view addSubview:tabbar.view];
so it got room to present its view only in parent controllers view thus got cut its navigation bar.
so to hack it I kept tab selected and instead of presenting it in selected view controller,have presented it in main view controller only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文