如何使用 objective c 在 iOS 中设置起始 viewcontroller.xib
How to set a starting viewcontroller.xib in iOS using objective c
我是 iOS 的新手。我创建了一个单一视图应用程序。它有一个视图控制器。编译应用程序时,它显示我的视图控制器的全黑颜色。现在我需要的是如何将我的视图控制器初始化为第一个视图控制器以及我需要初始化我的应用程序的导航控制器。注意:我创建了 xib 视图控制器。
在AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
HomeViewController *homeVc = [[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:homeVc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
打开ViewController.xib。 Select 文件所有者占位符。打开身份检查器并将 class 更改为 ViewController。
打开连接检查器并连接视图插座。
更新 AppDelegate。
AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
我是 iOS 的新手。我创建了一个单一视图应用程序。它有一个视图控制器。编译应用程序时,它显示我的视图控制器的全黑颜色。现在我需要的是如何将我的视图控制器初始化为第一个视图控制器以及我需要初始化我的应用程序的导航控制器。注意:我创建了 xib 视图控制器。
在AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
HomeViewController *homeVc = [[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:homeVc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
打开ViewController.xib。 Select 文件所有者占位符。打开身份检查器并将 class 更改为 ViewController。
打开连接检查器并连接视图插座。
更新 AppDelegate。
AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}