Akh*_*K C 140 xcode storyboard ios xcode6
Xcode6Empty Application在创建新项目时删除了模板.我们如何Xcode6在早期版本中创建一个空的应用程序(没有Storyboard)?
Akh*_*K C 269
XCode6对于直接创建空应用程序的版本,XCode5以及之前没有选项.但是我们仍然可以在不Storyboard遵循以下步骤的情况下创建应用程序
Single View Application.Main.storyboard和LaunchScreen.xib(选择它们,右键单击,然后选择从项目中删除它们,或者完全删除它们).Info.plist.Swift 3及以上:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
self.window?.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
Swift 2.x:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
Objective-C的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.rootViewController = [[ViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
S1L*_*IOR 32
一个简单的方法是复制XCode 5的Empty Application模板XCode的模板目录.
您可以下载XCode 5的Empty Application从模板这里,然后将其解压缩并复制到/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application目录中.
PS这种方法也适用于swift!
编辑
正如@harrisg在下面的评论中所建议的那样,您可以将上述模板放在~/Library/Developer/Xcode/Templates/Project Templates/iOS/Application/文件夹中,以便即使Xcode得到更新也可以使用它.
如果没有这样的目录,那么你可能必须创建这个目录结构:Templates/Project Templates/iOS/Application/in~/Library/Developer/Xcode/
使用这种简单的方法我可以创建一个Empty Applicationin XCode 6.(下面的截图)
希望这可以帮助!
Nik*_*ita 17
还有一些步骤需要做:
所以这是一个完整的教程:
将"[app name] -Prefix.pch"文件添加到包含内容的支持文件中:
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Run Code Online (Sandbox Code Playgroud)将"$ SRCROOT/$ PROJECT_NAME/[pch文件名]"添加到项目设置 - >构建设置 - > Apple LLVM 6.0 - 语言 - >"前缀标题"
实施application:didFinishLaunchingWithOptions:方法:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
Run Code Online (Sandbox Code Playgroud)Nil*_*ott 16
阿基尔斯的回答是完全正确的.对于我们这些使用Swift的人来说,它会是这样的:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
小智 10
还有一个步骤需要做:
1)删除plist文件中的主故事板文件基本名称
//AppDelegate.h
@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UINavigationController *nav;
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {`enter code here`
// Override point for customization after application launch.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIWindow *window = [[UIWindow alloc] initWithFrame:screenBounds];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[window setRootViewController: self.nav];
[window makeKeyAndVisible];
[self setWindow:window];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
删除Main.storyboard文件
可以简单地将其删除。
更新ProjectName-Info.plist文件
拔下Main storyboard base file name钥匙。
创建一个nib文件并链接到项目的视图控制器
1.创建一个笔尖文件(文件–>新建–>文件–>视图)
2,将File's Owner's类更新为项目的视图控制器
3.将File's Owner's view出口链接到viewnib文件中的对象
更新应用程序委托
1,导入项目的视图控制器的头文件
2.更新申请:didFinishLaunchingWithOptions:方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
为Xcode 8和Swift 3.
只需删除该.storyboard文件,它将自动删除您的相应参考,.plist并在您AppDelegate.swift添加以下代码.
Run Code Online (Sandbox Code Playgroud)let initialViewController = UIViewController() initialViewController.view.backgroundColor = .white window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = initialViewController window?.makeKeyAndVisible()
您可以编写自己的定制ViewCountroller和使用在AppDelegate.swift为你的self.window?.rootViewController,只是你自己的ViewController更换的UIViewController在上面的代码.
Xcode 9.3.1和Swift 4
之后,转到AppDelegate.swift并在didFinishLaunchingWithOptions函数中编写以下内容:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: ViewController())
return true
}
Run Code Online (Sandbox Code Playgroud)更新:Swift 5和iOS 13:

SceneDelegate.swift并func scene从以下位置更改:func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
Run Code Online (Sandbox Code Playgroud)
至
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).x
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = ViewController()
self.window = window
window.makeKeyAndVisible()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72391 次 |
| 最近记录: |