gpt4 book ai didi

iphone - 必须为单 View 应用程序应用选项卡栏

转载 作者:行者123 更新时间:2023-11-29 04:09:32 25 4
gpt4 key购买 nike

我使用 xcode4.2,在单 View 应用程序中为选项卡栏添加了 3 个项目。

问题是我无法可视化输出,而不是在 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

最佳答案

只需以这种方式更新您的应用程序代码即可。

<强>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。 UI更改

现在转到 xib 文件以获取我们要添加 TAB 的 View Controller ,只需在界面构建器中更改此方式

Bottom Bar = Tab Bar

enter image description here

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

如果您有任何问题,请随时问我。

关于iphone - 必须为单 View 应用程序应用选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14638205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com