Xcode5使用Main.storyboard作为navigation根目录

因为习惯了使用代码写界面,偶尔一次使用控件,记录一下。

最新的Xcode5 使用Main.storyboard作为默认。

首先新建一个项目,选择Single View Application


然后,一路next。工程项目建立完成


打开storyboard


选择一个Navigation Controller拖到图中区域

可以看到,如图。

然后,删除Root View Controller

右击Navigation Controller ,把root 链接到 view Controller上,把上图的箭头放到Navigation左边



现在分析一下,如果,建立完工程后,你直接在代码中,

- (IBAction)action:(id)sender {
    NSLog(@"self.navigationController is %@",self.navigationController);
    FirstViewController *first = [[FirstViewController alloc] init];
    [self.navigationController pushViewController:first animated:YES];
}

你会发现,self.navigaitonController is null,因为没有初始化。之前,我们在代码中的初始化为,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    MainViewController *mainViewController = [[MainViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    return YES;
}

所以,我们需要,添加一个navigation Controller,设置rootViewController所以出现了上边的操作。

但是,如果你没有把箭头拖到navigation Controller,那还会打印 self.navigaitonController is null,因为此时程序首先加载的还是Main.storyboard。

转载是请保留:来自http://blog.csdn.net/ralbatr


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Xcode中制作LaunchScreen.storyboard可以通过以下步骤进行: 1. 打开Xcode并创建一个新的项目或打开现有的项目。 2. 在项目导航栏中,找到并选中名为LaunchScreen.storyboard的文件。 3. 在Interface Builder中,你将看到一个可视化的画布,用于创建你的Launch Screen界面。 4. 你可以在右侧的对象库中选择和拖拽各种视图元素到画布上,比如标签、图像视图、按钮等等。根据你的需求,自定义你的Launch Screen界面。 5. 使用自动布局和约束来确保你的Launch Screen在各种设备和屏幕尺寸下都能正确显示。你可以使用Auto Layout来指定视图之间的关系和位置,以及对内容进行自适应布局。 6. 添加所需的背景图像或启动图像。你可以在图像资源选项卡中,将你的图像文件拖拽到LaunchScreen.storyboard上,并将其设置为背景图像或者其他所需的位置。 7. 根据需要,你可以使用动画效果或过渡效果来提高Launch Screen的可视化效果。这可以通过在Launch Screen上添加动画视图或切换视图的方式来实现。 8. 在你完成Launch Screen的设计和布局后,你可以选择在应用程序设置中将其设置为你的项目的主要启动界面。进入“General”选项卡,找到“App Icons and Launch Images”部分,选择“Launch Screen File”并选择你的Launch Screen.storyboard文件。 通过以上步骤,你可以使用Xcode中的Interface Builder创建和设计Launch Screen.storyboard,以实现你想要的启动界面效果。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值