Hiding a UINavigationController's UIToolbar during viewWillDisappear:

后端 未结 11 1724

I\'ve got an iPhone application with a UITableView menu. When a row in the table is selected, the appropriate view controller is pushed onto the application\'s

11条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 21:36

    I had the same problem and here is the solution that worked for me. Say you're pushing SomeUIViewController onto your navigation stack.

    Define this (private) ivar in the interface of SomeUIViewController:

    // keep a reference to the navigation controller for use in viewDidDisappear:(BOOL)animated method
    UINavigationController * _navigationController; 
    

    Implement the following methods of SomeUIViewController:

    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        // here, your controller still has a reference to self.navigationController
        _navigationController = [self.navigationController retain];
    }
    
    - (void)viewDidDisappear:(BOOL)animated {
        // at this point, self.navigationController = 0x0, so
        // use your retained reference to the navigation controller to perform any last minute operations, then release
    
        [_navigationController setToolbarHidden:YES];
        [_navigationController release];
    
        [super viewDidDisappear:animated];
    }
    

    The idea is that you want to hide the toolbar owned by the navigation controller after SomeUIViewController's view has disappeared. This way, you avoid any unwanted display artifacts.

    DISCLAIMER

    This is merely an answer that shows a workaround solution for the stated question. It is meant solely to point out a detail of the inner workings of the framework. It is also meant as an example of what not to submit to the Apple AppStore.

提交回复
热议问题