我的NavBar有些奇怪

时间:2012-11-01 06:43:55

标签: iphone objective-c ios xcode

我有一个带TabBarController的iPhone应用程序,每个标签都有一个导航控制器..其中一个导航控制器推送到另一个ViewController。在该View Controller中,我试图隐藏后退按钮并放置我的一个自定义按钮。在

- (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;

但是第一次应用程序被推出时,我第一次看到NavBar的后退按钮,但是稍后我每次打开应用程序时按钮仍然是我的自定义按钮。 (以及当我导航它是我的习惯) 有人?

1 个答案:

答案 0 :(得分:0)

试试这个..

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

[self.navigationController.navigationItem setHidesBackButton:YES];

self.navigationController.navigationItem.backBarButtonItem = nil;