我可能在这里做错了什么,因为这看起来有点愚蠢。
我在我的 UINavigationController 上设置了一个自定义 titleView(以 UILabel 的形式),它在每个页面上都是相同的。为此,我在我的应用程序委托中创建了一个函数来正确显示标签。然后,在我将其推送到导航堆栈之后,我在任何子视图上调用此函数。
这是代码(这可能比我的解释更有意义):
//In MyAppDelegate.m:
- (void)showTitleForNavigationController:(UINavigationController*) navController {
UILabel *label = [[UILabel alloc] init];
// set up label attributes
// ...
[label sizeToFit]; //without this line my label won't show at all
[navController.navigationBar.topItem setTitleView:label];
[label release];
}
// In SomeViewController.m, when pushing another controller onto the stack:
UIViewController *otherViewController = //initialize other view controller;
[self.navigationController pushViewController:otherViewController animated:YES];
[(MyAppDelegate*)[[UIApplication sharedApplication] delegate] showTitleForNavigationController:otherViewController.navigationController];
我的问题是,当我将下一个视图控制器推入堆栈时,新控制器平滑地滑过,在动画的整个持续时间内,标签都会粘在左上角,然后在动画完成后最终卡入到位。它看起来真的很奇怪和丑陋。如何正确设置标签,使其从下一个视图顺利滑动?当然,我错过了一些简单的事情......