我在做這將有3頁使UITabBar不增加在的appDelegate文件
- 登錄頁面的應用程序 - 第一頁的應用程序加載
我的第一頁後 - 當用戶成功登錄然後他進入此頁面。此頁面
包含具有兩個UITabBarItems的UITabBar。第一個是連接到我的第一頁
,另一個我的第二頁。
我的第二頁 - 這是另一個UIViewController。
我已經做出登錄頁面,但我無法找到解決UITabBar在我的第一頁添加
請幫我
我在做這將有3頁使UITabBar不增加在的appDelegate文件
我的第一頁後 - 當用戶成功登錄然後他進入此頁面。此頁面
包含具有兩個UITabBarItems的UITabBar。第一個是連接到
我的第一頁
,另一個我的第二頁。
我的第二頁 - 這是另一個UIViewController。
我已經做出登錄頁面,但我無法找到解決UITabBar在我的第一頁添加
請幫我
定義 AppDelegate.h
@property (strong, nonatomic) UITabBarController *tabBarController;
在AppDelegate.m
didFinishLaunchingWithOptions
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
self.tabBarController.selectedIndex=0;
self.tabBarController.delegate=self;
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
return YES;
}
現在,當你得到下面的代碼登錄成功寫在方法
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
delegate.tabBarController = [[UITabBarController alloc] init];
delegate.tabBarController.selectedIndex = 0;
delegate.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
delegate.tabBarController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:delegate.tabBarController animated:YES];
嘗試了這一點,
想這是LoginViewController.m
-(IBAction)loginButtonClicked:(id)sender
{
[self createTabBarView];
}
//Create TabBar View here
-(void)createTabBarView
{
NSMutableArray *tabItems = [NSMutableArray array];
UIViewController *firstViewController = [[FirstViewController alloc] init];;
firstViewController = @"First View";
firstViewController = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
[tabItems addObject:firstViewController];
UIViewController *secondViewController = [[SecondViewController alloc] init];;
secondViewController = @"Second View";
secondViewController = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];
[tabItems addObject:secondViewController];
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.viewControllers = tabItems;
self.tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:tabBarController animated:YES];
}
謝謝,
Nikhil。
您使用的是界面構建器嗎? 從我的角度來看,我寧願使用編程方式來實現它。
//In the appDidFinishLaunch method
BOOL loggedIn = [[NSUserDefault standDefault]boolForKey:"userlogin"];
if(loggedIn)
{
//Setup your UITabbarViewController
}
else
{
//Setup your loginView Controller
}
登錄後在LogInViewController
- (void)didLogin
{
YourAppDelegate *delegate = [UIApplication shareApplication].delegate;
[delegate.window addSubView:self.tabBarViewController.view];
[delegate.window removeSubView:self.view]
//Other Config
}
你應該在的地方,你可以識別登錄成功完成創建的TabBar。這個方法應該是你的loginViewController的一部分。 創建一個如下所示的函數來創建一個Tabbar並將其顯示在loginController上。
-(void) createTabBarController
{
UITabBarController *tabBar = [[UITabBarController alloc]init];
UIViewController *firstViewController = [[[UIViewController alloc] init]autorelease];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
[email protected]"First Controller";
firstNavController.tabBarItem.image = [UIImage imageNamed:@"first.png"];
UIViewController *secondViewController = [[[UIViewController alloc] init]autorelease];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];
[email protected]"First Controller";
secondNavController.tabBarItem.image = [UIImage imageNamed:@"first.png"];
[tabBar setViewControllers:[NSArray arrayWithObject:firstNavController,secondNavController,nil]];
[firstNavController release];
[secondNavController release];
[self presentModalViewController: tabBar];
[tabBar release];
}
您可以在appDelegate上添加tabbar,讓登錄頁面隱藏tabbar,並且不隱藏viewControllers的其餘部分。 – waheeda 2012-07-18 06:29:08
感謝Waheeda幫助:) – ChArAnJiT 2012-07-20 10:12:58