2012-11-20 16 views
5

我是iPhone開發新手。我正在開發一個TabBarViewcontroller應用程序(iPhone和iPad),並且我創建了一個LoginViewController和一個按鈕操作。 我的期望是點擊該按鈕後,控件將從LoginViewController移動到TabBarViewController。在這TabBarViewcontroller我有5個Tabbar(項目)ViewControllers。 這可能嗎?如何將按鈕動作連接到Tabbar Viewcontrollers

如果可以,請分享您的想法。

回答

7

首先,採取UINavigationControllerUITabbarControllerMainWindow.xib並結合IBOutlet到各自的領域.. ANS設置LoginViewController爲RootViewController的你UINavigationController的..

然後在didFinishLaunchingWithOptions方法中寫下這個..

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

現在AppDelegate.m這樣創造另一種方法..

-(void)loadApplication 
{ 
    [navController pushViewController:tabbarController animated:NO]; 
} 

上的登錄按鈕動作..調用此方法如下..

-(IBAction)btnLoginTapped:(id)sender 
{ 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 
    [appDelegate loadApplication]; 
} 
+0

它的工作.. tnx您的想法 –

5

所以在按鍵操作嘗試以下代碼

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
appDelegate.window.rootViewController = tabBarController; 
+0

@ Ramesh.GR是它解決問題了嗎? –

+0

偉大的工作...... Tnx爲您的想法。 –

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]; 
    } 

把這個方法放在AppDelegate.m文件中,並在任何viewController例如在LoginView控制器 當你想添加的TabBar然後聲明委託的對象,並調用這個方法就像波紋管..

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
[appDelegate addTabBarControllerInwindow]; 
+0

Tnx爲您的答案..我用這個代碼它爲我工作... AppDelegate * appDelegate = [[UIApplication sharedApplication]委託]; appDelegate.window.rootViewController = tabBarController; –

+0

@ Ramesh.GR總是wel-come隊友.. :) upvote或accpet回答,如果它對你有用.. –

1

我想你可能在一個單一的項目中尋找多個VC。因此,在appDelegate中爲loginVC和其他VC(用於tabbar)聲明和初始化VC,並在登錄成功後調用以下函數。

上啓動使LoginVC爲RootViewController的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{// declare LoginVC and make it rootViewController 
self.window.rootViewController = self._loginVCObj; 
    [self.window makeKeyAndVisible]; 
} 

#pragma mark- Continue to next screen after successful Login

-(void) continueToNextView 
{ // Handle UI after Login like. 
[_loginVCObj._indicator stopAnimating]; 
    [_loginVCObj._loginButton setEnabled:YES]; 
//add the VC to the tabbar 
    self._tabBarController.viewControllers = [NSArray arrayWithObjects:self.navigationControllerList,_favItemListNavObj, _toDoHereVC, _settingNavObj, nil]; 
// make tabbar as rootViewController 
    self.window.rootViewController = self._tabBarController; 
} 
+0

Tnx爲你的答案...我用這個代碼它的工作..對我.. AppDelegate * appDelegate = [ [UIApplication sharedApplication]委託]; appDelegate.window.rootViewController = tabBarController; –

+0

@ Ramesh.GR很高興聽到這一點。請享用。 – HDdeveloper

相關問題