如何将Button Action连接到Tabbar Viewcontrollers

GR.*_*GR. 5 iphone objective-c ipad ios

我是iPhone开发的新手.我正在开发一个TabBarViewcontroller应用程序(iPhone和iPad),我已经创建了一个LoginViewController和一个按钮动作.我的期望是点击该按钮后,控件将从中移动LoginViewController到TabBarViewController.在这里TabBarViewcontroller我有5个Tabbar(项目)ViewControllers.可能吗?

如果可以,请分享您的想法.

Meh*_*tri 7

首先,采取UINavigationController与UITabbarController你MainWindow.xib并绑定IBOutlet到各自的领域.. ANS设置LoginViewController为你的RootViewController的UINavigationController..

然后在didFinishLaunchingWithOptions方法中写这个..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [self.window setRootViewController:navController];
    [self.window makeKeyAndVisible];    
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

现在AppDelegate.m像这样创建其他方法..

-(void)loadApplication
{
    [navController pushViewController:tabbarController animated:NO];
}
Run Code Online (Sandbox Code Playgroud)

在您的登录按钮操作..调用此方法如下..

-(IBAction)btnLoginTapped:(id)sender
{
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [appDelegate loadApplication];
}
Run Code Online (Sandbox Code Playgroud)


Sus*_*nta 5

所以在按钮操作中尝试以下代码

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
appDelegate.window.rootViewController = tabBarController;
Run Code Online (Sandbox Code Playgroud)


Par*_*shi 5

使用此方法从任何其他视图添加tabbar ..

    -(void)addTabBarControllerInwindow 
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];

        [self.navigationController.view removeFromSuperview];
        [self.window addSubview:tabBarController.view];
        [UIView commitAnimations];
    }
Run Code Online (Sandbox Code Playgroud)

将此方法放在AppDelegate.m文件和任何viewController中,例如在LoginView Controller中,当你想添加tabbar然后声明委托对象并调用此方法时,如下所示..

 AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
 [appDelegate addTabBarControllerInwindow];
Run Code Online (Sandbox Code Playgroud)