【发布时间】:2013-10-22 12:52:24
【问题描述】:
我在使用导航堆栈推送视图时遇到了一些问题。
我遇到的问题是,在触摸标签栏项目后,视图控制器被推入导航堆栈(来自名为 FirstViewController 的视图控制器),如下所示:
- (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;
}
【问题讨论】:
-
这是 TabBarController 的 viewDidLoad 吗?完成按钮在哪里?
-
请在 tabBarItem 的触摸事件或 tabBarContoller 的触摸委托中分享您的代码,无论您的第一个视图控制器的推送逻辑是否存在?
-
你好 Kunal,这是 FirstViewController 的 viewDidLoad 一个空的 UIView 类。 (@interface FirstViewController : UIViewController) 另外我在触摸事件中没有任何代码,因为我在 appDelegate didFinishLaunchingWithOptions 中以编程方式添加了所有控件。
-
那么选择标签栏项目有什么代码吗?
标签: iphone ios objective-c uiviewcontroller pushviewcontroller