按钮未显示在导航栏项目中
我已经使用基于导航的应用程序模板创建了一个项目,并做了一些工作并运行了它。
我预计如果我触摸一个单元格,将显示新视图,并且新图标(返回按钮)也会显示在导航栏项目上。
但由于某种原因,“后退按钮”不会自动添加。可能是什么问题?
下面是我的代码。
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能还没有给父控制器一个标题(只是 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.
你是说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.
看来您尚未在导航位置的视图中设置导航栏标题...
默认情况下设置导航栏标题后,它将显示后退按钮
在 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";