0

我有一个带有 TabBarController 的 iPhone 应用程序,每个选项卡都有一个导航控制器。其中一个导航控制器推送到另一个视图控制器。在那个视图控制器中,我试图隐藏后退按钮并放置我的一个自定义按钮。在里面

- (void)viewDidLoad
{
    [super viewDidLoad];
    self._allUsersParticipantsInTheVideo = [[NSMutableArray alloc] init];
    self._allUsersInvitesInTheVideo = [[NSMutableArray alloc] init];

    for (int i=0; i < [self._curVideoToShow._videoParticipants count]; i++) {
        [self._allUsersParticipantsInTheVideo addObject:[self._curVideoToShow._videoParticipants objectAtIndex:i]];
    }
    for (int i=0; i < [self._curVideoToShow._videoInvitees count]; i++) {
        [self._allUsersInvitesInTheVideo addObject:[self._curVideoToShow._videoInvitees objectAtIndex:i]];
    }

    [self setNavBar];
}

#pragma mark - Set NavBar

-(void)setNavBar{
    self.navigationItem.hidesBackButton = YES;

    UIView *navBarItemview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    [navBarItemview setBackgroundColor:[UIColor clearColor]];

    // Set cutsom back button
    //UIImage *backImage = [UIImage imageNamed:@"backButton.png"];
    UIImage *backImage = [UIImage imageNamed:@"LeftArrowBg.png"];
    CGRect frame = CGRectMake(0, 6, backImage.size.width + 4, backImage.size.height);
    UIButton *bttn = [[UIButton alloc] initWithFrame:frame];
    [bttn setBackgroundImage:backImage forState:0];
    [bttn setTag:kBackBttn];
    [bttn setTitle:@"Back" forState:UIControlStateNormal];
    [bttn setTitleEdgeInsets:UIEdgeInsetsMake(4, 5, 0, 0)];
    [bttn.titleLabel setFont:[UIFont fontWithName:@"PTSans-Bold" size:12.0]];
    [bttn setContentMode:UIViewContentModeScaleAspectFit];
    [bttn addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    [navBarItemview addSubview:bttn];


    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 4, 320, 40)];
    [titleLbl setFont:[UIFont fontWithName:@"PTSans-Bold" size:24.0]];
    [titleLbl setTextColor:[UIColor whiteColor]];
    [titleLbl setTextAlignment:UITextAlignmentCenter];
    [titleLbl setBackgroundColor:[UIColor clearColor]];
    [titleLbl setTag:kTitleLbl];
    [titleLbl setShadowOffset:CGSizeMake(0, 1)];
    [titleLbl setShadowColor:[UIColor blackColor]];
    [titleLbl setText:@"All Participants"];

    [navBarItemview addSubview:titleLbl];
    self.navigationItem.titleView = navBarItemview;
}

如您所见,我写过:

self.navigationItem.hidesBackButton = YES;

但是在第一次启动应用程序时,我只第一次看到导航栏的后退按钮,但后来每次我打开应用程序时,按钮仍然是我的自定义按钮。(而且当我导航时这是我的习惯)有人吗?

4

1 回答 1

0

试试这个..

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationItem.hidesBackButton = YES;
}

或者

[self.navigationController.navigationItem setHidesBackButton:YES];

或者

self.navigationController.navigationItem.backBarButtonItem = nil;
于 2012-11-01T07:04:13.653 回答