ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用

前端之家收集整理的这篇文章主要介绍了ios – UINavigationBar -pushNavigationItem在将新控制器推送到UINavigationController堆栈时从不调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我今晚正在做一些测试来查看原生UINavigationBar的行为.我创建了一个简单的代码片段,它执行以下操作:
- (void)pushController {
    PHViewController *ctrl2 = [[[PHViewController alloc] initWithNibName:@"PHViewController" bundle:nil] autorelease];
    ctrl2.shouldShowPrompt = YES;
    [self.viewController pushViewController:ctrl2 animated:YES];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    PHViewController *ctrl = [[[PHViewController alloc] initWithNibName:@"PHViewController" bundle:nil] autorelease];
    ctrl.shouldShowPrompt = YES;
    ctrl.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Push" 
                                                                           style:UIBarButtonItemStyleDone
                                                                          target:self
                                                                          action:@selector(pushController)] autorelease];

    self.viewController = [[[PHNavigationController alloc] initWithRootViewController:ctrl] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

现在我已经将UINavigationController的UINavigationBar子类化了(我知道这是非法的,这是一个教育问题)我已经覆盖了以下方法

- (void)setItems:(NSArray *)items animated:(BOOL)animated {
    NSLog(@"Setting Navigation Item");
    [super setItems:items animated:animated];
}

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated  {
    NSLog(@"Pushing Navigation Item");
    [super pushNavigationItem:item animated:animated];
}

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated {
    NSLog(@"Poping Navigation Item");
    return [super popNavigationItemAnimated:animated];
}

- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
    NSLog(@"Setting Value: %@ for keyPath:%@",value,keyPath);
    [super setValue:value forKeyPath:keyPath];
}

这是我的问题:为什么控制台中存在“弹出导航项”(因此被调用方法)和“推送导航项”不是?

解决方法

我找到了原因:它调用 – (void)pushNavigationItem:(UINavigation *)项不调用 – (void)pushNavigationItem:animated!

还是非常感谢!

猜你在找的iOS相关文章