【发布时间】:2014-04-04 07:28:34
【问题描述】:
- (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];
}
上面给出了我的代码:我面临的问题是,当我第一次导航到主页时,导航右栏按钮项不可见。当我导航到其他页面并返回时,它是可见的。第一种方法用于创建右导航栏按钮项。
【问题讨论】:
-
检查
self.navigationTableViewController.navigationItem是否为nil。 -
@KudoCC 谢谢伙计,但它不是 nil,如果它是 nil,按钮不应该出现在从视图返回时。
-
你最好在
self.centreViewController的viewWillAppear方法中配置导航栏或尝试将[self setRightNavigationBarViewForUser];这一行移到navigateToHome方法的底部(确保添加弹出动作后的项目,也许它应该进入completionHandler)
标签: ios objective-c uinavigationbar uinavigationitem