Hiding a UINavigationController's UIToolbar during viewWillDisappear:

后端 未结 11 1727

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:44

    Try implementing a UINavigationControllerDelegate and setting it to your navigation controller's delegate property. This achieved for me what you are describing in your post, with no visible artifacts.

    The following code assumes that secondController is pushed into the navigation view by an action performed in the firstController.

    MyNavigationControllerDelegate.h

    @interface MyNavigationControllerDelegate : NSObject {
    }
    
    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
    -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
    
    @end
    

    MyNavigationControllerDelegate.m

    #import "MyNavigationControllerDelegate.h"
    #import "AppDelegate_Shared.h"
    
    @implementation MyNavigationControllerDelegate
    
    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if ([AppDelegate_Shared sharedDelegate].firstController  == viewController ) {
            [navigationController setNavigationBarHidden:TRUE];
            [navigationController setToolbarHidden:FALSE];
        }
    }
    
    -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if ([AppDelegate_Shared sharedDelegate].secondController == viewController ) {
            [navigationController setNavigationBarHidden:FALSE];
            [navigationController setToolbarHidden:TRUE];
        }
    }
    
    @end
    

    sharedDelegate is just a helper method:

    AppDelegate_Shared.m

    + (AppDelegate_Shared*)sharedDelegate {
        return (AppDelegate_Shared*)[[UIApplication sharedApplication] delegate];
    }
    

提交回复
热议问题