swift-碰到的问题

如何让工程不使用storyboard和scene

在这里插入图片描述
删除info.plist里面的Application Scene mainifest
删除SceneDelegate.swift
删除AppDelegate.swift里面的这两个方法

 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

然后在appDelegate,swift里面添加

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?//添加window

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        window = UIWindow(frame: UIScreen.main.bounds)  
        // 设置根视图控制器
        var VC = UIViewController()
        VC.view.backgroundColor = UIColor.blue
          let rootViewController = VC  // 替换为你的视图控制器
          window?.rootViewController = rootViewController
        window?.makeKeyAndVisible()//让window可以被看见
        
        return true
    }

}


当点击一个button时显示出下一个ViewController

在这里插入图片描述
点击注册后跳转到
在这里插入图片描述
左上角自动会有返回的按钮
可以直接在IB界面在添加了VavigationViewController的ViewController里面的button,直接拉线到另一个VC就可以实现这个功能

首先需要将loginViewController包含进一个navigationViewController里面
创建登录button的行为 为

self.navigationController?.pushViewController(registerVC, animated: true)//registerVC为需要显示出来的VC

协议不能使用默认值怎么办

protocol MyProtocol {
    func myMethod(type:Int)
}

extension MyProtocol {
    func myMethod(tyope:Int = 0) {
        print("Default implementation")
    }
}

struct MyStruct: MyProtocol {
    // MyStruct 可以选择使用默认实现
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值