iphone 4.3导航栏问题
我现在正在开发一个同时支持 iOS 4.3 和 5.0 的应用程序。
我的代码在 5.0 中运行良好,但在 4.3 中导致了一个棘手的错误。
问题是:
我有一个包含 tableView 的视图。该视图有一个导航栏,其中包含左侧和右侧导航栏项目。一旦我选择表视图中的行(并到达其相应的视图)并返回,左侧和右侧导航栏项目都会“消失”。
过去几个小时我一直在经历这个混乱,有人能治愈吗?
这是我已经完成的:
这是我在视图加载时调用的实用方法。
+ (void)setNavigationBarContents:(UIViewController *)view
{
UIImage *topBarimage=[UIImage imageNamed:NAVIGATION_BAR_IMAGE];
if([view.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[view.navigationController.navigationBar setBackgroundImage:topBarimage forBarMetrics:UIBarMetricsDefault];
}
else
{
[view.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:topBarimage] aboveSubview:view.navigationController.navigationBar];
}
UIImage *logo=[UIImage imageNamed:LOGO];
UIImageView *logoView=[[UIImageView alloc]initWithImage:logo];
view.navigationItem.titleView = logoView;
UIImage *settingsButtonImage= [UIImage imageNamed:NAVIGATION_SETTINGS];
UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[rightBarButton setBackgroundImage: settingsButtonImage forState:UIControlStateNormal];
[rightBarButton addTarget: view action:@selector(settingsButton:) forControlEvents:UIControlEventTouchUpInside];
rightBarButton.frame = CGRectMake(0, 0, 50, 40);
view.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton];
UIImage *logoutButtonImage= [UIImage imageNamed:LOGOUT];
UIButton *leftBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[leftBarButton setBackgroundImage: logoutButtonImage forState:UIControlStateNormal];
[leftBarButton addTarget: view action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];
leftBarButton.frame = CGRectMake(0, 0, 65, 32);
view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: leftBarButton];
}
尝试在 viewDidLoad 和 viewWillAppear 中调用它,但徒劳。
这就是我在 viewController 中的调用方式。
- (void)viewDidLoad
{
[super viewDidLoad];
//other setups here.
[Utility setNavigationBarContents:self];
}
I am now developing an app which support both iOS 4.3 and 5.0.
My code works fine with 5.0, but results in a tricky-bug in 4.3.
Issue is:
I've got a view with a tableView in it. This view have a navigation bar with both left and right navigation bar items. Once I select the row in table view (and reaches it's corresponding view) and returns back, both the left and right navigation-bar items "vanish".
I've been over this mess for last few hours, some one got a cure?
This is what I have already done:
This is the utility method that I call when view loads.
+ (void)setNavigationBarContents:(UIViewController *)view
{
UIImage *topBarimage=[UIImage imageNamed:NAVIGATION_BAR_IMAGE];
if([view.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[view.navigationController.navigationBar setBackgroundImage:topBarimage forBarMetrics:UIBarMetricsDefault];
}
else
{
[view.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:topBarimage] aboveSubview:view.navigationController.navigationBar];
}
UIImage *logo=[UIImage imageNamed:LOGO];
UIImageView *logoView=[[UIImageView alloc]initWithImage:logo];
view.navigationItem.titleView = logoView;
UIImage *settingsButtonImage= [UIImage imageNamed:NAVIGATION_SETTINGS];
UIButton *rightBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[rightBarButton setBackgroundImage: settingsButtonImage forState:UIControlStateNormal];
[rightBarButton addTarget: view action:@selector(settingsButton:) forControlEvents:UIControlEventTouchUpInside];
rightBarButton.frame = CGRectMake(0, 0, 50, 40);
view.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightBarButton];
UIImage *logoutButtonImage= [UIImage imageNamed:LOGOUT];
UIButton *leftBarButton = [UIButton buttonWithType: UIButtonTypeCustom];
[leftBarButton setBackgroundImage: logoutButtonImage forState:UIControlStateNormal];
[leftBarButton addTarget: view action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];
leftBarButton.frame = CGRectMake(0, 0, 65, 32);
view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: leftBarButton];
}
Have tried calling this both in viewDidLoad and viewWillAppear, but in vain.
This is how I call this in viewController.
- (void)viewDidLoad
{
[super viewDidLoad];
//other setups here.
[Utility setNavigationBarContents:self];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过添加得到了解决方案
我的 appDelegate.m 中的这段代码
I got the solution by adding
This code in my appDelegate.m