Xcode11后,新创建的项目无法进入Main.storyboard问题

Xcode11新建项无法使用Main.storyboard

 

Xcode11之后,新创建的项目会自动创建SceneDelegate文件
如果删除这个文件后,项目将无法进入到Main.storyboard中。

 

解决方法:在info.plist文件中搜索SceneDelegate,会搜索到Application Scene Manifest下存在这个文件名,直接删除即可,正常进入Main.storyboard中。

 

SceneDelegate的作用

在Xcode11以后新建项目会自动创建SceneDelegate文件

主要是:

iOS13中appdelegate的职责发现了改变:
iOS13之前,AppDelegate的职责全权处理App生命周期和UI生命周期;
iOS13之后,AppDelegate的职责是:
1、处理 App 生命周期
2、新的 Scene Session 生命周期

而SceneDelegate的指责是:

1、管理UI的生命周期

因此初始化window方法需要改变:
现在不再Appdelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions进行初始化,转交给SceneDelegatewillConnectToSession:方法进行根控制器设置:

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {

    UIWindowScene *windowScene = (UIWindowScene *)scene;
    self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
    self.window.frame = windowScene.coordinateSpace.bounds;
    self.window.rootViewController = [UITabBarController new];
    [self.window makeKeyAndVisible];
}

所以在新创建的项目中如果删除SceneDelegate,则要修改info.plist文件中的SceneDeleagte配置

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
创建九宫格的步骤如下: 1. 创建一个新的 Xcode 项目,选择 Single View Application。 2. 在 Main.storyboard 中添加一个 UICollectionView。在 Attributes Inspector 中将 Scroll Direction 设置为 Vertical。 3. 在 UICollectionViewCell 中添加一个 UILabel,将其居中,并设置它的控制点约束(Control Point Constraints)为 0。 4. 在 Attributes Inspector 中将 Cell Size 设置为 100 x 100,Minimum Spacing 设置为 0。 5. 在 ViewController.swift 中添加以下代码: ``` import UIKit class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { @IBOutlet weak var collectionView: UICollectionView! let items = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] override func viewDidLoad() { super.viewDidLoad() collectionView.dataSource = self collectionView.delegate = self } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return items.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell cell.label.text = items[indexPath.row] return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print("You selected cell #\(indexPath.item + 1)") } } class CustomCell: UICollectionViewCell { @IBOutlet weak var label: UILabel! } ``` 6. 在 Main.storyboard 中选择 UICollectionViewCell,将其 Class 设置为 CustomCell,并将 Identifier 设置为 cell。 这样,你就可以在模拟器中运行你的应用程序,看到一个九宫格了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值