导航控制器不添加后退按钮

发布于 2024-10-18 06:38:22 字数 531 浏览 2 评论 0 原文

我有一个视图将新视图推送到屏幕上。

当显示新视图时,导航控制器中没有后退按钮。

我在一个视图中有以下内容

在此处输入图像描述

我使用以下代码推送一个新视图

[photoViewController setAsset:[assets objectAtIndex:(cell.rowNumber * 4) + index]];
[[self navigationController] pushViewController:photoViewController animated:YES];
[photoViewController release];

当视图出现时以下是可见的

如何添加后退按钮以及在哪里添加相同的共享按钮到栏在第二个视图中?

谢谢。 :)

I have a view which pushes a new view onto the screen.

When the new view is shown, there is no back button in the navigation controller.

I have the following in one view

enter image description here

and I push a new view using the following code

[photoViewController setAsset:[assets objectAtIndex:(cell.rowNumber * 4) + index]];
[[self navigationController] pushViewController:photoViewController animated:YES];
[photoViewController release];

When the view appears the following is visible

enter image description here

How do I add the back button and where would I add the same share button to the bar in the second view?

Thanks. :)

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

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

发布评论

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

评论(4

Hello爱情风 2024-10-25 06:38:22

您需要在第一个视图中设置标题。后退按钮使用上一个视图的标题。如果未设置,则不会显示后退按钮。

在第一个视图的 viewDidLoad 方法中,使用 self.title = @"title";

You need to set a title in your first view. The back button uses the title of the previous view. If one is not set then the back button will not be displayed.

In the viewDidLoad method of your first view, use self.title = @"title";

刘备忘录 2024-10-25 06:38:22

奇怪的是,推送控制器的导航栏中没有显示后退按钮,因为这是标准的开箱即用行为,免费为您提供一个。您的 photoViewController 尚未覆盖 -(UINavigationItem*)navigationItem;,是吗?

至于将“共享”按钮添加到第二个控制器,您可以在加载视图时通过控制器的 navigationItem 属性来设置它:

// In the .m file of whatever class photoViewController is...  
- (void)viewDidLoad {

    UIBarButtonItem* rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(doSomething:)];
    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];
    [rightBarButtonItem release];
}

您可以使用相同的方法来设置自定义后退按钮,只需为自己获取另一个 UIBarButtonItem 并设置它即可作为 UINavigationItem 的 leftBarButtonItem。

It's odd that there is no back button displayed in the navigation bar for the pushed controller, because it is standard, out-of-the-box, behavior to give you one for free. Your photoViewController hasn't overridden -(UINavigationItem*)navigationItem;, has it?

As for adding the "Share" button to the second controller, you can just set it through the controller's navigationItem property when the its view loads:

// In the .m file of whatever class photoViewController is...  
- (void)viewDidLoad {

    UIBarButtonItem* rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(doSomething:)];
    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];
    [rightBarButtonItem release];
}

You can use the same approach to set a custom back button, just get yourself another UIBarButtonItem and set it as the leftBarButtonItem of your UINavigationItem.

葬花如无物 2024-10-25 06:38:22

尝试在项目可执行文件的环境变量中使用 NSZombieEnable ,这将帮助您进行调试。通常会发生这种崩溃,因为数组包含的元素少于您指定的数量。我认为您需要使用此代码所以......

[photoViewController setAsset:[assets objectAtIndex:(cell.rowNumber * 4) + index]];

并且还将断点放入表视图方法中,在索引路径中选择行,在索引路径中选择行的单元格以及行数,希望您能够弄清楚

Try to use the NSZombieEnable in your enviornment variable in your projects executable ,this will help you to debug.Well this crash genrally occurs ,because array contains elements less then the count you are specifying.you need to work with your this code, i think so....

[photoViewController setAsset:[assets objectAtIndex:(cell.rowNumber * 4) + index]];

and also put the breakpoints in your table view method didselect row at index path,cell for row at index path and number of rows and hopefully you would be able to figure out

如歌彻婉言 2024-10-25 06:38:22

你不应该在 VIewDidLoad 上设置 backButton,而是在 DidSelect 上对其进行编码

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

    UIBarButtonItem *btn=[[UIBarButtonItem alloc]init];
btn.title=@"Back";
self.navigationItem.backBarButtonItem=btn;
[btn release];

  }

U should not set backButton on VIewDidLoad, instead u code it on DidSelect

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

    UIBarButtonItem *btn=[[UIBarButtonItem alloc]init];
btn.title=@"Back";
self.navigationItem.backBarButtonItem=btn;
[btn release];

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