简体   繁体   English

导航栏右栏按钮项不可见

[英]Navigation bar right bar button item is not visible

- (void)setRightNavigationBarViewForUser {
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
                               initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                               target:nil action:nil];
    spacer.width = 760;
    NSString *title = [VimondStore sessionManager].userName;

    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 144, 44)];
    tempView.backgroundColor = [UIColor clearColor];
    UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(4, 0, 44, 44)];
    tempImageView.image = [UIImage imageNamed:@"user.png"];

    UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(44, 0, 80, 44)];
    tempLabel.backgroundColor = [UIColor clearColor];
    tempLabel.text = title;
    tempLabel.font = [UIFont boldSystemFontOfSize:14.0];
    tempLabel.textColor = [UIColor whiteColor];
    tempLabel.textAlignment = NSTextAlignmentLeft;
    tempLabel.adjustsFontSizeToFitWidth = YES;
    tempLabel.minimumScaleFactor = 0.8;
    [tempView addSubview:tempImageView];
    [tempView addSubview:tempLabel];
    UIBarButtonItem *userView = [[UIBarButtonItem alloc]initWithCustomView:tempView];
    NSArray *items = @[spacer ,userView];
    self.navigationTableViewController.navigationItem.rightBarButtonItems = items;
}

- (void)navigateToHome {
    [self setRightNavigationBarViewForUser];
    self.loginViewController = nil;
    [self showCenterPanelAnimated:YES];
    [self setLeftBarButtonForDrawerTitle];
    NSAssert([self.centreViewController isKindOfClass:[GGBaseViewController class]], @"Must be of GGBaseViewController class");
    [GenreNavigator navigateToRoot:(GGBaseViewController*)self.centreViewController completionHandler:nil];
}

My code is given above: The problem, I am facing is that navigation right bar button items are not visible first time when I navigate to home. 上面给出了我的代码:我面临的问题是,当我第一次导航到首页时,导航右栏按钮项不可见。 When I navigate to some other page and comes back then its visible. 当我导航到其他页面并返回时可见。 The first method is used to create right navigation bar button items. 第一种方法用于创建右导航栏按钮项。

From Apple doc on rightBarButtonItems, you can see that most likely your custom view is too wide and your button is not showing because it does not fit. 从rightBarButtonItems的Apple文档中,您可以看到您的自定义视图很可能太宽了,并且按钮不显示,因为它不合适。 Test making it narrower and see if it appears? 测试使其变窄,看是否出现?

Discussion This array can contain 0 or more bar button items to display on the right side of the navigation bar. 讨论此数组可以包含0个或多个要在导航栏右侧显示的栏按钮项。 Items are displayed right-to-left in the same order as they appear in the array. 项目以与阵列中出现的顺序从右到左显示。 Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item. 因此,数组中的第一个项目是最右边的项目,其他项目则添加到前一个项目的左边。

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not displayed. 如果没有足够的空间来显示数组中的所有项目,则不会显示与标题视图(如果存在)重叠的内容或条形左侧的按钮。

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

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