0

I am loading a mapview. I have created a barbutton in the bottombar toolbar of the view, setting its identifier as pagecurl. As expected, a barbutton with page curl icon is loaded. From this mapview I move to anotherv view, by clicking on annotations in the mapview. And then I return to the mapview. At that time my pagecurl barbutton icon(pagecurl icon) is not displayed, and my barbutton width is also reduced. I am not able to figure out the problem.

- (void)viewDidLoad
{
    [super viewDidLoad];

    if(isSingleContactSelected)
    {
        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        self.navigationItem.leftBarButtonItem = self.cancelButton   ;
        [self.cancelButton setTarget:self];
        [self.cancelButton setAction:@selector(onClose:)];

        [addressFieldSearchBar setFrame:CGRectMake(66, 0, 256, 44)];
        addressFieldSearchBar.delegate =self;

        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        [self.navigationController.navigationBar addSubview:addressFieldSearchBar];

        [searchDirectionSegmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        UIBarButtonItem *searchDirectionSegmentedButton = [[UIBarButtonItem alloc] initWithCustomView:searchDirectionSegmentedControl];

        flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        NSArray *toolbarItems = [NSArray arrayWithObjects: compassButton , flexibleSpace, searchDirectionSegmentedButton, flexibleSpace, pageButton, nil];
        [self setToolbarItems:toolbarItems];

        self.navigationController.toolbarHidden = NO;
        [compassButton release];
        [pageButton release];
        [searchDirectionSegmentedControl release];

        mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        mapView.delegate=self; 

        [self.view addSubview:mapView]; 
    }
}

- (void)viewDidUnload{
    [super viewDidUnload];    
}

-(void) viewWillAppear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.navigationController.navigationBar setHidden:NO];
        [self.navigationController.toolbar setHidden:NO];
        [self.navigationController.toolbar setBarStyle:UIBarStyleDefault];
        [self.addressFieldSearchBar setHidden:NO];
    }
}

-(void) viewWillDisappear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.addressFieldSearchBar setHidden:YES];
        [self.navigationController.toolbar setHidden:YES];
    }
}
7
  • I have added the code. I set the property of the barbutton through the xib file. Dec 1, 2011 at 9:10
  • move your code for setting toolbar inside viewWillAppear: method. Dec 10, 2011 at 14:07
  • @XaviValero when you say "move to another view", do you mean a new VC is pushed into the navigation controller or just add/remove another view on the mapView?
    – mr.pppoe
    Dec 13, 2011 at 9:25
  • @mr.pppoe .... A new VC is pushed Dec 13, 2011 at 9:30
  • @XaviValero Have you done anything to the navigationController.toolbar in the new VC, in its viewWillAppear/viewWillDisappear. I met a similar issue in iOS 5 SDK, just want to find out whether you are in the same case.
    – mr.pppoe
    Dec 13, 2011 at 10:04

2 Answers 2

1
+50

Though its a long shot, it could be something to do with the setHidden calls in your appear and disappear methods.

[self.navigationController.toolbar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];

The best way to do this using UIViewController's "-setHidesBottomBarWhenPushed:" method.

Maybe try some NSLog() in -viewWillAppear:

// If pageButton is an instance variable
NSLog(@"%@",pageButton);

// Enumerate through all toolbar items.
// Check to see if NSLog output differs after pushing/popping this view controller.
for (UIBarButtonItem *item in [self.navigationController.toolbar.items])
{
    NSLog(@"%@",item);
}
1
  • The same issue has popped up again and this time I cant handle it. Jan 24, 2012 at 12:27
0

setHidesBottomBarWhenPushed method did the trick in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.