我有一个基于导航的iPhone应用程序。 通常你从RootViewController开始,在那里你可以从UITableView中选择一行,它将你带到另一个ViewController,我们称之为SecondLevelViewController。
当应用程序启动时,我检查它是否从SecondLevelViewController退出(通过保存到defaultUserSettings的参数)。如果是,我想再次显示SecondLevelViewController。
为实现这一目标,我在我的申请代表中进行了检查
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法,
之后[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
然后我将SecondLevelViewController添加到视图堆栈。我用pushViewController和setViewControllers尝试了它:
SecondLevelViewController *newVC = [[SecondLevelViewController alloc] initWithNibName:@"SecondLevelView" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObjects:[self.navigationController.viewControllers objectAtIndex:0], newVC, nil]
animated:YES];
该应用随后会显示所需的视图。 现在问题是:SecondLevelViewController在导航栏的左侧显示一个后退按钮。使用上述方式时,不会出现此按钮。 我的结论是,当我进入SecondLevelViewController时,RootViewController尚未完全初始化。这可能吗?我怎么能避免这个?
谢谢, 标记
答案 0 :(得分:0)
是.......这是假的..... 你可以做这件事......像这样......
根据您的设置检查条件,它直接来自RootViewController,然后在SecondLevelViewController的导航栏中放置一个自定义后退按钮/栏按钮。
在此之前你需要检查条件......如果它是真的使用使用自定义按钮
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Back :));
(void)返回:(id)发件人{
[self.navigationController popToRootViewControllerAnimated:YES]; }
我认为这对你来说肯定有用。