Ios 导航栏右栏按钮项不可见
上面给出了我的代码:我面临的问题是,当我第一次导航到主页时,导航右栏按钮项不可见。当我导航到其他页面并返回时,它是可见的。第一种方法用于创建右导航栏按钮项。从RightBarButtonims上的Apple doc中,您可以看到,您的自定义视图很可能太宽,并且您的按钮没有显示,因为它不适合。试着让它变窄,看看它是否出现了 讨论 此数组可以包含0个或多个要显示在导航栏右侧的栏按钮项。项目从右到左的显示顺序与它们在阵列中的显示顺序相同。因此,数组中的第一项是最右边的项,其他项添加到前一项的左边Ios 导航栏右栏按钮项不可见,ios,objective-c,uinavigationbar,uinavigationitem,Ios,Objective C,Uinavigationbar,Uinavigationitem,上面给出了我的代码:我面临的问题是,当我第一次导航到主页时,导航右栏按钮项不可见。当我导航到其他页面并返回时,它是可见的。第一种方法用于创建右导航栏按钮项。从RightBarButtonims上的Apple doc中,您可以看到,您的自定义视图很可能太宽,并且您的按钮没有显示,因为它不适合。试着让它变窄,看看它是否出现了 讨论 此数组可以包含0个或多个要显示在导航栏右侧的栏按钮项。项目从右到左的显示顺序与它们在阵列中的显示顺序相同。因此,数组中的第一项是最右边的项,其他项添加到前一项的左边 如果
如果没有足够的空间显示数组中的所有项目,则不会显示与标题视图(如果存在)或栏左侧按钮重叠的项目。检查
self.navigationTableViewController.navigationItem
是否为零。@KudoCC谢谢,但不是零,如果是nil,则从视图返回时不应出现按钮。您最好在self中配置导航栏。centreViewController的视图将出现方法或尝试移动此行[self-setRightNavigationBarViewForUser]
到方法的底部navigateToHome
(请确保在pop操作之后添加项目,也许它应该放在completionHandler中)当我从家里导航到任何其他地方并返回时,它会显示参考。视图完美如我所愿。但当我第一次导航到家时,它不会显示。可能是因为在您导航回家后,您正在更改左侧按钮栏,并且有更多的空间?正如我所说,尝试暂时缩小项目,以确认这是一个宽度问题。
- (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];
}