300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > storyboard搭建项目_用Storyboard实例化控制器:

storyboard搭建项目_用Storyboard实例化控制器:

时间:2021-04-19 14:45:16

相关推荐

storyboard搭建项目_用Storyboard实例化控制器:

步骤一:手动初始化storyboard.首先删除系统自动创建的ViewController.h, ViewController.m 和 main.storyboard这三个文件。

2.点击项目——>General——>Deployment Info,在Main Interface选项中将main删除。

3.新建一个Storyboard文件,拖一个控制器,在拖一个按钮。点击storyboard上方的导航条,在右侧“属性”栏下view Controller复选框中Title下方将“Is Initial View Controller”勾选上。

4. 在AppDelegate.m文件中的didFinishLaunchingWithOptions方法中填写下面代码:

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

// 1. Create a window

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

// 2. Create Controller(A StoryBoard)

UIStoryboard*story = [UIStoryboardstoryboardWithName:@"Storyboard"bundle:nil];

// 2.1 Instantiate Controller (With Sweet(jian tou))

UIViewController*vc = [storyinstantiateInitialViewController];

// 3. Set the window Root Controller

self.window.rootViewController= vc;

// 4. Put the window as the Main Window and visible

[self.windowmakeKeyAndVisible];

returnYES;

}

步骤二:通过标记初始化storyboard。首先删除系统自动创建的ViewController.h, ViewController.m 和 main.storyboard这三个文件。

2.点击项目——>General——>Deployment Info,在Main Interface选项中将main删除。

3.新建一个Storyboard文件,拖一个控制器,在拖一个按钮。点击storyboard上方的导航条,在右侧“属性”栏左侧选项中identity选项下storyboard ID里填写“Vstar”,之后点击回车键。

4. 在AppDelegate.m文件中的didFinishLaunchingWithOptions方法中填写下面代码:

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

// 1. Create a window

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

// 2. Create Controller(A StoryBoard)

UIStoryboard*story = [UIStoryboardstoryboardWithName:@"Storyboard"bundle:nil];

// 2.1 Instantiate Controller (With Sweet(jian tou))

UIViewController*vc = [storyinstantiateViewControllerWithIdentifier:@"Vstar"];

// 3. Set the window Root Controller

self.window.rootViewController= vc;

// 4. Put the window as the Main Window and visible

[self.windowmakeKeyAndVisible];

returnYES;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。