网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
07月31日漏签0天
swift吧 关注:40,521贴子:75,416
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 8回复贴,共1页
<<返回swift吧
>0< 加载中...

请教下,Swift中如何改变RootController?

  • 只看楼主
  • 收藏

  • 回复
  • aluzi992
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我接手的一个老项目,OC的,有个代码:
self.window.rootViewController = nav
就是切换窗口,现在我要改为Swift,结果我发现ViewController里面已经没有window属性了?
那要怎么写呢?


  • 风居住的街道
  • 高级粉丝
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
window.rootViewController不是可以去到跟控制器吗


2025-07-31 06:19:24
广告
不感兴趣
开通SVIP免广告
  • 阳光般的小骚男
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
let ** = UIWindow()
**.rootViewController
这样行不行?


  • 风居住的街道
  • 高级粉丝
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼


  • 风居住的街道
  • 高级粉丝
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
window = UIWindow.init(windowScene: scene as! UIWindowScene)
window?.frame = UIScreen.main.bounds
let tabVc = YQQRootTabbarController.init()
window?.rootViewController = tabVc
window?.backgroundColor = .white
window?.makeKeyAndVisible()
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 8回复贴,共1页
<<返回swift吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示