开发者

UITabBar's navigationbar hides navigationbar when view is presented modally

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?


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];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜