-(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'是否爲零。 – KudoCC
@KudoCC感謝的人,但它不是零,如果它是零按鈕不應該出現從視圖返回。 –
你最好在'self.centreViewController'的'viewWillAppear'方法中配置導航欄,或者嘗試將這一行'[self setRightNavigationBarViewForUser];'移動到方法'navigateToHome'的底部(確保你添加了項目在流行動作之後,也許它應該完成處理程序) – KudoCC