[英]How can i use xib files instead of storyboard in Xcode 5?
我是ios开发的新手,我观看的许多教程都遵循xib方法,因为它们是在XCode 5之前录制的。我如何在单视图应用程序中使用xib方法? 当我删除故事板并选择其中一个xib作为主界面时,它无法正常工作。 谢谢你的提示。
添加新文件,选择cococatouch并选择Objective -C类,然后转到下一个单击。
你显示下面的屏幕
在底部必须选择with xib for user Interface.and next
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:
@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;
}
创建新项目时选择清空应用程序模板 。
从左窗格中选择Cocoa touch - > objective-c class - >然后给出viewController的名称和Xib用户界面的tick选项。
然后在appDelegate文件中应用以下代码:
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文件:
- (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
你可以按照以下步骤做到: -
在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];
礼貌: - MKR
https://stackoverflow.com/a/19633059/1865424
检查一下,你错过了任何一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.