简体   繁体   English

如何在Xcode 5中使用xib文件而不是storyboard?

[英]How can i use xib files instead of storyboard in Xcode 5?

I'm very new to ios developing and many of the tutorials i watch follow the xib approach since they were recorded before XCode 5. How can i go with the xib approach in Single View Application? 我是ios开发的新手,我观看的许多教程都遵循xib方法,因为它们是在XCode 5之前录制的。我如何在单视图应用程序中使用xib方法? When i delete storyboard and select one of the xib's as the main interface it's not working. 当我删除故事板并选择其中一个xib作为主界面时,它无法正常工作。 Thanks for any tip. 谢谢你的提示。

add new file in that select the cococatouch and select the Objective -C class and then go to the next click. 添加新文件,选择cococatouch并选择Objective -C类,然后转到下一个单击。
you show the below screen 你显示下面的屏幕
at the bottom must select the with xib for user Interface.and next 在底部必须选择with xib for user Interface.and next

AppDelegate.h: AppDelegate.h:

@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    ViewController *viewObj;
    UINavigationController *navObj;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic)  ViewController *viewObj;
@property (strong, nonatomic) UINavigationController *navObj;

AppDelegate.m: AppDelegate.m:

@synthesize viewObj,window,navObj;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    viewObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    navObj = [[UINavigationController alloc] initWithRootViewController:viewObj];

    window.rootViewController=navObj;
    [window makeKeyAndVisible];

    return YES;
}

在此输入图像描述

Select Empty application template while creating new project. 创建新项目时选择清空应用程序模板
Select Cocoa touch from left pane -> objective-c class -> then give name of viewController and tick option of Xib user interface. 从左窗格中选择Cocoa touch - > objective-c class - >然后给出viewController的名称和Xib用户界面的tick选项。

and then in apply below code in appDelegate file: 然后在appDelegate文件应用以下代码:

appDelegate.h File: appDelegate.h文件:

#import <UIKit/UIKit.h>
#import "HomeViewController.h"

@interface HomeAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic)HomeViewController *homeViewController;
@property (strong,nonatomic)UINavigationController *navigationController;

appDelegate.m File: appDelegate.m文件:

- (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];

    self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.homeViewController];
    self.window.rootViewController = self.navigationController;


    [self.window makeKeyAndVisible];
    return YES;
}

  @end

you can do it by following these steps:- 你可以按照以下步骤做到: -

  • Create a new project 创建一个新项目
  • Select Single View Application 选择单一视图应用程序
  • Set ProjectName and other settings 设置ProjectName和其他设置
  • Save Project at location 将项目保存在位置
  • Select Project in Navigator Panel in Left 在左侧的导航器面板中选择项目
  • Remove Main.storyboard file from project 从项目中删除Main.storyboard文件
  • Add New .xib file in Project 在Project中添加新的.xib文件
  • Set Main Interface to your .xib file in "General Tab" on right panel. 在右侧面板的“常规选项卡”中将主界面设置为.xib文件。
  • Paste following code in didFinishLaunchingWithOptions method didFinishLaunchingWithOptions方法中粘贴以下代码

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

Courtesy:- MKR 礼貌: - MKR

https://stackoverflow.com/a/19633059/1865424 https://stackoverflow.com/a/19633059/1865424

Just check it have you missed any of the step. 检查一下,你错过了任何一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM