按钮未显示在导航栏项目中

发布于 2024-10-18 13:57:08 字数 818 浏览 0 评论 0原文

我已经使用基于导航的应用程序模板创建了一个项目,并做了一些工作并运行了它。

我预计如果我触摸一个单元格,将显示新视图,并且新图标(返回按钮)也会显示在导航栏项目上。

但由于某种原因,“后退按钮”不会自动添加。可能是什么问题?

下面是我的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Navigation logic may go here -- for example, create and push another view controller.
    MessageView *detailViewController = [[MessageView alloc] initWithNibName:@"MessageView" bundle:nil];

    NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
    detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];

    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

I've created a project with Navigation-based Application template, and did some work and ran it.

I expected if I touch a cell, new view will show up and new icon (which is going back button) will show up on navigation-bar item too.

But for some reason, the 'back button' is not added automatically. What can be the problem??

Below is my code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Navigation logic may go here -- for example, create and push another view controller.
    MessageView *detailViewController = [[MessageView alloc] initWithNibName:@"MessageView" bundle:nil];

    NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
    detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];

    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

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

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

发布评论

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

评论(3

深陷 2024-10-25 13:57:08

您可能还没有给父控制器一个标题(只是 viewDidLoad 或 viewWillAppear 中的 self.title = @"my name" )。这就是后退按钮中默认填写的内容,因此如果您不命名它,则不会获得后退按钮。

You probably haven't given your parent controller a title (just self.title = @"my name" in viewDidLoad or viewWillAppear). That's what gets filled in by default in the back button, so if you don't name it, you don't get a back button.

渡你暖光 2024-10-25 13:57:08

你是说MessageView是从UIView继承的。但我认为如果推入导航控制器没有问题那么它将是 UIViewController 的子类。

不显示后退按钮有一些原因:-

1.) 正如 Mackworth 所说,您没有给出任何您要导航的标题。

2.) 您的导航栏的后退按钮属性设置为隐藏。

否则后退按钮应该出现在导航栏上。

You are saying that MessageView is inherited from UIView. But I think if there's no problem to push into the navigation controller then it would be UIViewController's subclass.

There are some reasons for not displaying back button:-

1.) As Mackworth told that you have not given any title from which you are navigating.

2.) your Navigation Bar's back button property is set for hidden.

Otherwise back button should be appear on the navigation bar.

策马西风 2024-10-25 13:57:08

看来您尚未在导航位置的视图中设置导航栏标题...

默认情况下设置导航栏标题后,它将显示后退按钮

在 ViewDidLoad 或 ViewWillAppear 中使用它。

self.navigationItem.title=@"在此设置您的标题";

It seems you haven't set your Navigation Bar Title in the View from where you are navigating...

Once you set the title of navigationbar by default it will show you the back button

Use it in either ViewDidLoad or ViewWillAppear.

self.navigationItem.title=@"Set Your Title here";

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