The button element is lost when the toolbar is hidden and hidden.

I do not know why the button disappears after the toolbar is installed to hide and show. how can i fix this?

set button code

-(void)viewDidAppear:(BOOL)animated {
    //NSLog(@"viewDidAppear ");

    [self becomeFirstResponder];
    //Create a button
    UIBarButtonItem *back = [[UIBarButtonItem alloc] 
                        initWithBarButtonSystemItem:UIBarButtonSystemItemRewind 
                target:self action:@selector(goback:)];

    UIBarButtonItem *fixspace1 = [[UIBarButtonItem alloc] 
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                 target:self action:nil];

    UIBarButtonItem *next = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward 
                             target:self action:@selector(gofwd:)];
    UIBarButtonItem *stop = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemStop 
                             target:self action:@selector(stopload:)];

    UIBarButtonItem *refresh = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 
                             target:self action:@selector(refreshWeb:)];


    [self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
    [self.navigationItem setRightBarButtonItem:refresh animated:YES];

    [self.navigationController.view addSubview:self.navigationController.toolbar];

    [stop release];
    [next release];
    [back release];
    [refresh release];
    [fixspace1 release];
}

and I customize my button with this method

-(void)viewDidAppear:(BOOL)animated 

this code is used for a hidden toolbar

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
    [self.navigationController setToolbarHidden:YES animated:YES];

alt text

+3
source share
3 answers

documented method for customizing toolbar items through the toolbarItems property of the view controller . In the same UINavigationController Reference , the property is also indicated toolbaras read-only and specifically warning

UIToolbar .

[self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];

[self setToolbarItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
+9

, . :

[self.navigationController.view addSubview:self.navigationController.toolbar];

- , iPhone SDK. , ? , .

+1

, . dealloc.

0

Source: https://habr.com/ru/post/1736645/


All Articles