Iphone 在选定的选项卡栏项目上轻触两次可隐藏当前视图控制器
我在使用导航堆栈推送视图时遇到一些问题 我遇到的问题是,在触摸选项卡栏项后,视图控制器被推入导航堆栈(来自名为FirstViewController的视图控制器),如下所示:Iphone 在选定的选项卡栏项目上轻触两次可隐藏当前视图控制器,iphone,ios,objective-c,uiviewcontroller,pushviewcontroller,Iphone,Ios,Objective C,Uiviewcontroller,Pushviewcontroller,我在使用导航堆栈推送视图时遇到一些问题 我遇到的问题是,在触摸选项卡栏项后,视图控制器被推入导航堆栈(来自名为FirstViewController的视图控制器),如下所示: - (void)viewDidLoad { [super viewDidLoad]; svc = [[SecondViewController alloc] init]; [self.navigationController pushViewController:svc animated:YES];
- (void)viewDidLoad
{
[super viewDidLoad];
svc = [[SecondViewController alloc] init];
[self.navigationController pushViewController:svc animated:YES];
}
这与预期的一样,但当再次触摸同一选项卡栏项目时,实际问题会出现
当这种情况发生时,当前视图(先前按下的SecondViewController)被移除,就像我触摸“完成”按钮一样
我找不到发生这种情况的地点和原因
编辑:这是我设置选项卡栏、视图控制器和导航的方式:
@implementation AppDelegate
@synthesize HomeViewController, FirstViewController, SecondViewController, ThirdViewController, SettingsViewController, tabBarController, window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
FirstViewController *firstViewController = [[FirstViewController alloc]
initWithNibName:nil bundle:nil];
UINavigationController *firstViewControllerNav = [[UINavigationController alloc]
initWithRootViewController:firstViewController];
SecondViewController *secondViewController = [[SecondViewController alloc]
initWithNibName:nil bundle:nil];
UINavigationController *secondViewControllerNav = [[UINavigationController alloc]
initWithRootViewController:secondViewController];
ThirdViewController *thirdViewController = [[ThirdViewController alloc]
initWithNibName:nil bundle:nil];
UINavigationController *thirdViewControllerNav = [[UINavigationController alloc]
initWithRootViewController:thirdViewController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[firstViewControllerNav,
secondViewControllerNav];
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
[self.window setRootViewController:self.tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
触摸选项卡栏项目两次将导致导航控制器弹回到根视图控制器。这是预期的和内置的行为 为了防止这种情况,您必须使用 我相信这样做会奏效:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
return viewController != tabBarController.selectedViewController;
}
这是TabBarController的viewDidLoad吗?“完成”按钮在哪里?请在tabBarItem的触摸事件或TabBarController的触摸委托中共享您的代码,无论first view controller的推送逻辑在哪里?嗨,Kunal,这是FirstViewController的viewDidLoad一个空UIView类。(@interface FirstViewController:UIViewController)我在touch事件中也没有任何代码,因为我在appDelegate didFinishLaunchingWithOptions中以编程方式添加所有控件。那么有没有关于选择选项卡栏项的代码?好的,有没有方法覆盖此行为?我应该以不同的方式实现它吗?我认为这种行为适用于双击,这与对选定对象进行单次点击不同?感谢您的回复,为了应用该代码,我应该实现自定义选项卡栏控制器并添加该委托,对吗?@KunalBalani他提到“问题”在再次触摸同一选项卡栏项目时发生。@加斯特·纳尔盖否,只需在UITabBarController上设置委托并实现该方法。