我对ios开发非常陌生,我看的很多教程都是遵循Xib的方法,因为它们是在XCode 5之前录制的。如何在Single View Application中使用Xib的方法呢?当我删除Storyboard并选择一个Xib作为主界面时,它不起作用。感谢任何提示。
我对ios开发非常陌生,我看的很多教程都是遵循Xib的方法,因为它们是在XCode 5之前录制的。如何在Single View Application中使用Xib的方法呢?当我删除Storyboard并选择一个Xib作为主界面时,它不起作用。感谢任何提示。
在那里添加新文件,在选择CocoCatouch后选择Objective-C类,然后进入下一步。您将看到如下屏幕。
在底部必须选择使用XIB作为用户界面,然后点击下一步。
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类 -> 然后输入viewController的名称并选中Xib用户界面选项。
然后在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://dev59.com/5GIk5IYBdhLWcg3wDaQW#19633059
只需检查是否漏掉任何步骤。