简体   繁体   English

导航栏右按钮放置不正确

[英]Navigationbar right button is not placed correctly

I implemented a UITabBarController with 4 items. 我实现了带有4个项目的UITabBarController

I set the initial ViewController from AppDelegate . 我从AppDelegate设置了初始ViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    HomeTabBarViewController* homeVC = [[HomeTabBarViewController alloc] init];

    [self.window setRootViewController:homeVC];
    [self.window makeKeyAndVisible];

return YES;
}

Here is HomeTabBarViewController ViewDidLoad Code: 这是HomeTabBarViewController ViewDidLoad代码:

UIViewController *view1 = [[UIViewController alloc] init];
    [view1.view setBackgroundColor:[UIColor redColor]];
UIViewController *view2 = [[UIViewController alloc] init];
    UINavigationController * centerNav=[[UINavigationController alloc]initWithRootViewController:view1];
    HomePagingViewController * view3=(HomePagingViewController*)[storyboard instantiateViewControllerWithIdentifier:@"HomePagingViewController"];
     UINavigationController * centerNav3=[[UINavigationController alloc]initWithRootViewController:view3];
    UIViewController *view4 = [[UIViewController alloc] init];
    UINavigationController * centerNav4=[[UINavigationController alloc]initWithRootViewController:view4];
    [view2.view setBackgroundColor:[UIColor greenColor]];
    [view3.view setBackgroundColor:[UIColor purpleColor]];
    [view4.view setBackgroundColor:[UIColor grayColor]];
    NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
    [tabViewControllers addObject:centerNav];
    [tabViewControllers addObject:view2];
    [tabViewControllers addObject:centerNav3];
    [tabViewControllers addObject:centerNav4];

    [self setViewControllers:tabViewControllers];
    view1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home"
                                  image:[UIImage imageNamed:@"home_tab_item.png"] selectedImage:[UIImage imageNamed:@"home_tab_item_active.png"]] ;
    view2.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"Bookmark"
                                  image:[UIImage imageNamed:@"bookmark_tab_item.png"] selectedImage:[UIImage imageNamed:@"bookmark_tab_item_active.png"]];
    view3.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"Paper"
                                  image:[UIImage imageNamed:@"paper_tab_item.png"] selectedImage:[UIImage imageNamed:@"paper_tab_item_active.png"]];
    view4.tabBarItem =
    [[UITabBarItem alloc] initWithTitle:@"More"
                                  image:[UIImage imageNamed:@"menu_tab_item.png"] selectedImage:[UIImage imageNamed:@"menu_tab_item_active.png"]];

In HomePagingViewController ViewDidLoad I setUp a Navigation as in code HomePagingViewController ViewDidLoad我按照代码设置导航

-(void)navigationSetUp{
 self.navigationController.navigationBar.translucent=NO;

    UIBarButtonItem * settingBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
    UIBarButtonItem * searchBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
    self.navigationItem.leftBarButtonItem = settingBtn;
    self.navigationItem.rightBarButtonItem = searchBtn;
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ie_New_logo.png"]];
}

After this when I changed the tab for HomePagingViewController the navigation right button not placed correctly there is no margin from right. 此后,当我更改HomePagingViewController的选项卡时,导航右按钮未正确放置,从右开始没有空白。

Refer Image : 参考图片: 在此处输入图片说明

Please Help. 请帮忙。

I resolved the issue , there is no issue with the code . 我解决了这个问题,代码没有问题。 Actually for Epaper we using third party SDK So that this problem occur.I Removed SDK & the code is working fine now. 实际上,对于Epaper,我们使用了第三方SDK,因此会发生此问题。我删除了SDK,现在代码可以正常工作。

you should think UIBarButtonSystemItemFixedSpace effect. 您应该认为UIBarButtonSystemItemFixedSpace效果。

  • eg: 例如:
    UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

-- -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM