2013-02-01 60 views
0

使用xcode4.2的Iam我在单视图应用程序中为tabbar添加了3个项目。必须应用单视图应用程序的tabbar

的问题是我不能想象的输出,而不是一个黑色的屏幕显示在iOS模拟器

谁能帮我请

我的代码是

@synthesize window = _window; 
@synthesize viewController = _viewController; 
@synthesize appNavigation = _appNavigation; 

- (void)dealloc 
{ 
    [_window release]; 
    [_viewController release]; 
    [_appNavigation release];  
    [super dealloc]; 
} 



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 

      UITabBarController *tabController = [[UITabBarController alloc] init]; 
      NSMutableArray *tabsArray = [[NSMutableArray alloc] init]; 
      `enter code here`ViewController *homeScreen = [[ViewController alloc] init]; 
      homeScreen.navigationItem.title = @"App Title"; 
      _appNavigation = [[UINavigationController alloc]initWithRootViewController:homeScreen]; 
      _appNavigation.tabBarItem.title = @"Home"; 
      [_appNavigation.tabBarItem setImage:[UIImage imageNamed:@"Home_Button.png"]]; 
      [tabsArray addObject:_appNavigation]; 
      [_appNavigation release]; 

      BookmarksViewController *bookMark = [[BookmarksViewController alloc] init]; 
      bookMark.navigationItem.title = @"Bookmarks"; 
      _appNavigation = [[UINavigationController alloc] initWithRootViewController:bookMark]; 
      [_appNavigation.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:2]; 
      _appNavigation.tabBarItem.title = @"Bookmarks"; 
      [tabsArray addObject:_appNavigation]; 
      [_appNavigation release]; 

      AppSettingsController *settings = [[AppSettingsController alloc] initWithStyle:UITableViewStyleGrouped]; 
      settings.navigationItem.title = @"Settings"; 
      _appNavigation = [[UINavigationController alloc] initWithRootViewController:settings]; 
      _appNavigation.tabBarItem.title = @"Settings"; 
      [_appNavigation.tabBarItem setImage:[UIImage imageNamed:@"Settings_Button.png"]]; 
      [tabsArray addObject:_appNavigation]; 
      [_appNavigation release]; 

      SearchViewController *searchView = [[SearchViewController alloc] init]; 
      searchView.navigationItem.title = @"Ranga"; 
      _appNavigation = [[UINavigationController alloc] initWithRootViewController:searchView]; 
      _appNavigation.tabBarItem.title = @"Search"; 
      [_appNavigation.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemSearch tag:4]; 
      [tabsArray addObject:_appNavigation]; 
      [_appNavigation release]; 


      tabController.viewControllers = tabsArray; 


LoginViewController *loginView = [[LoginViewController alloc] init]; 

      [self.window addSubview:tabController.view]; 

[tabController presentModalViewController:loginView animated:NO]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 


@end 
+0

请张贴您的代码。 –

+0

我已经采取单视图应用程序出故事板,我有xib文件there.i分别添加3个视图控制器我有.h .m和.xib文件。 – user1986984

回答

1

只需更新您的应用程序代码这条路。

1码变化

开放AppDelegate.h文件应该像

#import <UIKit/UIKit.h> 

@class FirstViewController,SecondViewController; 


@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> 


@property (strong, nonatomic) UIWindow *window; 

//these two view controllers (screens) for adding to tabs. 
@property (strong, nonatomic) FirstViewController *firstViewController; 
@property (strong, nonatomic) SecondViewController *secondViewController; 

//this will be the tab bar-controller 
@property (strong, nonatomic) UITabBarController *baseTabBarController; 

@end 

现在您AppDelegate.m文件中的代码应该是这样

#import "AppDelegate.h"  
#import "FirstViewController .h" 
#import "SecondViewController.h" 


@implementation AppDelegate 

@synthesize window = _window; 
@synthesize firstViewController; 
@synthesize secondViewController; 
@synthesize baseTabBarController; 



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // create tab bar 
    baseTabBarController = [[UITabBarController alloc]init]; 

    baseTabBarController.delegate=self; 

    // initialize first screen 
    firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController " bundle:nil]; 
    UINavigationController *homeView = [[UINavigationController alloc]initWithRootViewController:firstViewController]; 
    firstViewController.title = @"Home "; 

    // initialize second screen 
    secondViewController = [[SecondViewController alloc] initWithNibName:@"FavViewController" bundle:nil]; 
    secondViewController.title = @"My Favourite"; 
    UINavigationController *favouriteView = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 

    //add both views in array 
    NSArray *controllers = [NSArray arrayWithObjects:homeView,favouriteView, nil]; 
    //add array to tab bar 
    baseTabBarController.viewControllers = controllers; 
    //add tab bar to window 
    self.window.rootViewController = baseTabBarController; 


    [self.window makeKeyAndVisible];  

    return YES; 
} 

2. in U我改变

现在去厦门国际银行文件为我们要添加TAB两个视图控制器, 只是改变这种方式在Interface Builder

底酒吧=标签栏

enter image description here

就是这样!您将在应用程序的底部获得两个选项卡。 enter image description here

随意问我是否有任何问题。

+0

谢谢你我知道了。我有一个小小的怀疑。第六个bottonbar没有设置为tabbar,我也可以查看tabbar添加。那么它的用途是什么? – user1986984

+0

@ user1986984在这里很棒:)如果我的答案帮助了你,PL接受答案(在左边打一个绿色的刻度标记),它的工作原理是在IB中不添加tabbar,但它会干扰你的UI项目,因为它会在运行时以编程方式添加TabBar,所以我们在添加TabBar时设计我们的布局,因此它在运行时会与我们一样设计整个U – swiftBoy

+0

好的谢谢你的信息.. – user1986984

相关问题