后退导航按钮未显示在推送视图控制器中

发布于 2024-09-13 07:11:42 字数 1172 浏览 3 评论 0原文

我有一个问题,我可以从根视图控制器成功推送新的视图控制器(使用使用核心数据模板的基于导航的应用程序),但详细视图(与根视图控制器分开的 xib 文件)却不能。 t 显示后退导航按钮。我确信我已经在 IB 中完成了所有正确的连接,并且其他一切都按预期工作。

RootViewController.h

@class ItemsViewController;

@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {

IBOutlet ItemsViewController *itemsVC;

}

@property (nonatomic, retain) IBOutlet ItemsViewController *itemsVC;

@end

RootViewController.m

#import "ItemsViewController.h"

@synthesize itemsVC;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Pushes to ItemsViewController

ItemsViewController *itemsViewController = [[ItemsViewController alloc] initWithNibName:@"ItemsViewController" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:itemsViewController animated:YES];
[itemsViewController release];

}

ItemsViewController 是一个 UITableViewController 子类,有自己的 xib,也称为 ItemsViewController。再次,它从 RootViewController 推送,但后退按钮没有显示像这样。我的印象是这是使用导航控制器的“免费”功能。正如您所料,这是一个非常令人沮丧的障碍,我将不胜感激任何帮助。

I have a problem where I can successfully push a new view controller from my root view controller (using the Navigation-based application using Core Data template), but the detail view, which is a separate xib file from the root view controller, doesn't display the back navigation button. I'm certain that I've done all of the proper connections in IB, and everything else is working as expected.

RootViewController.h

@class ItemsViewController;

@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {

IBOutlet ItemsViewController *itemsVC;

}

@property (nonatomic, retain) IBOutlet ItemsViewController *itemsVC;

@end

RootViewController.m

#import "ItemsViewController.h"

@synthesize itemsVC;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Pushes to ItemsViewController

ItemsViewController *itemsViewController = [[ItemsViewController alloc] initWithNibName:@"ItemsViewController" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:itemsViewController animated:YES];
[itemsViewController release];

}

ItemsViewController is a UITableViewController subclass with its own xib, also named ItemsViewController. Again, it gets pushed from RootViewController, but the back button doesn't show up like this. I was under the impression that it was a "free" feature of using a navigation controller. As you might expect, this is a very frustrating roadblock and I would appreciate any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

各自安好 2024-09-20 07:11:42

您的 ItemsViewController 类是否在其 viewDidLoad 方法中设置了其 title 属性?

您应该调用 [tableView deselectRowAtIndexPath:indexPathAnimated:YES] 作为 tableView:didSelectRowAtIndexPath: 的最后一行,以符合 Apple 的人机界面指南。

Does your ItemsViewController class set its title property in its viewDidLoad method?

You should call [tableView deselectRowAtIndexPath:indexPath animated:YES] as the last line of tableView:didSelectRowAtIndexPath: to conform to Apple's human interface guidelines.

不羁少年 2024-09-20 07:11:42

是的,请确保您的 RootViewController 上有一个标题,如果没有,则不会出现任何按钮。以编程方式设置标题;

self.navigationItem.title = @"Hello Der";

Yeah, make sure you have a title on your RootViewController, if it doesn't no button will appear. To set a title programmatically;

self.navigationItem.title = @"Hello Der";
⒈起吃苦の倖褔 2024-09-20 07:11:42

为未来读者提供的一些额外信息:我在尝试在应用程序加载时重新填充导航层次结构时遇到了这个问题,因此我从应用程序委托的 application:didFinishLaunchingWithOptions: 方法调用 setViewControllers: 。我也遇到了同样的问题,后退按钮没有显示。

就我而言,在其 viewDidLoad 中设置根视图控制器的导航项标题不起作用,可能是因为其他视图首先加载并将根的标题视为空。相反,我在调用 setViewControllers: 之前在 application:didFinishLaunchingWithOptions: 方法中设置根视图控制器的导航项标题,并修复了它。

Some extra info for future readers: I ran into this problem while trying to re-populate a nav hierarchy on application load, so I was calling setViewControllers: from the app delegate's application:didFinishLaunchingWithOptions: method. And I was running into the same problem with the back button not showing up.

In my case, setting the root view controller's nav item title in its viewDidLoad did not work, presumably because the other views were loading first and seeing the root's title as null. Instead, I set the root view controller's nav item title in my application:didFinishLaunchingWithOptions: method right before I called setViewControllers:, and that fixed it.

请爱~陌生人 2024-09-20 07:11:42

如果您是个傻瓜并且错误地将视图初始化为模态视图而不是将视图推送到导航控制器,也可能会发生这种情况。

哎呀:[自我呈现ModalViewController:navController动画:是];
意思是:[self.navigationController PushViewController:控制器动画:是];

This can also happen if you're a bonehead and mistakenly initialize the view as modal instead of pushing a view to the navigation controller.

oops: [self presentModalViewController:navController animated:YES];
meant: [self.navigationController pushViewController:controller animated:YES];

甜点 2024-09-20 07:11:42

尝试以下片段。它对我有用!

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];

[self.navigationController.navigationBar bringSubviewToFront:[self.navigationController.navigationItem backBarButtonItem]];

Try following snippet. It work for me!

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];

[self.navigationController.navigationBar bringSubviewToFront:[self.navigationController.navigationItem backBarButtonItem]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文