我的应用中的主屏幕有2个按钮。单击按钮1时,显示ViewController1。单击按钮2时,显示ViewController2。 ViewController1有2个酒吧项目。每个条形项的ViewController都有“后退”和“完成”按钮。返回主菜单,Done用于隐藏键盘。我想控制2个这些按钮。 我有两个方向:
在主屏幕上添加导航控制器。它有后退按钮。 Button Done在每个条形项的ViewController中实现。在这种情况下,更改标签栏时按钮Done效果不佳。我看到了,首先点击标签栏,它工作正常,但点击Item1-> Item2-> Item1,这次按钮在Item1中完成不正确,因为它仍然是在Item2 Controller中完成的按钮。 在这种情况下如何解决?
我在主屏幕中隐藏导航控制器,在每个标签栏的控制器中实现导航控制器。在这种情况下,按钮Done工作正常,但按钮Back在单击时无法移动到主屏幕。 在这种情况下如何移动到主屏幕?
AppDelegate.m中的代码:
UIViewController *cont = [[VCMainMenu alloc]initWithNibName:@"VCMainMenu" bundle:nil];
self.navController = [[UINavigationController alloc]initWithRootViewController:cont];
[self.window setRootViewController:navController];
MainMenu.m中的代码,ViewDidLoad:
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
MainMenu.m中的代码,buttonClick:
self.navigationController.navigationBarHidden = YES;
[self.tab setSelectedIndex:0];
[self.navigationController pushViewController:self.tab animated:YES];
按钮完成每个课程:
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(btnDonePressed:)];
self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnDone;
btnDone.enabled = TRUE;
btnDone.style = UIBarButtonSystemItemDone;
感谢。
答案 0 :(得分:0)
要隐藏键盘,您需要知道哪个textView是firstResponder。您必须为每个场景实现dismisskeyboard方法。
另外,为什么要编写所有导航内容?通过故事板和分段来实现它们会容易得多。
答案 1 :(得分:0)
我在主屏幕中隐藏导航控制器,实现导航 每个标签栏的控制器中的控制器。在这种情况下,按钮完成 效果很好,但点击后按钮返回无法移动到主屏幕 它。在这种情况下如何移动到主屏幕?
为此,请使用
[self.navigationController popViewControllerAnimated:YES];
作为旁注@Marcal有一点意见,我认为如果你使用故事板和赛段可能会更好