我今晚正在做一些测试来看看当地人的行为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;
}
Run Code Online (Sandbox Code Playgroud)
现在我已经将UINavigationBar其分类UINavigationController(我知道这是非法的,这是一个教育问题),我已经覆盖了以下方法:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
这是我的问题:为什么控制台中存在"弹出导航项"(因此被调用的方法)和"推送导航项"不是?
Pie*_*ult 11
我找到了原因:它调用 - (void)pushNavigationItem:(UINavigation*)项不调用 - (void)pushNavigationItem:animated!
还是非常感谢!
| 归档时间: |
|
| 查看次数: |
2498 次 |
| 最近记录: |