我正在嘗試轉換(慢慢現代化)一個舊的 iOS 專案以支持 UISceneDelegate。然而,此刻舊的 appdelegate 創建了一個 UIWindow 并將一個 UIViewController 附加到了 finishedLaunching 中的 windows rootViewController。
由于我還沒有準備好將我的應用程式轉換為 Storyboards,但有沒有一種方法可以使用 UISceneDelegate 實作相同的結果?
請注意 mainViewController 不受 XIB 或故事板的支持,因此我的 info.plist 的 UIWindowSceneSessionRoleApplication 部分中沒有對任何 UI 檔案的參考
問候克里斯蒂安·斯托爾·安徒生
uj5u.com熱心網友回復:
在您的子類中實作以下方法UIWindowSceneDelegate來分配您的UIViewController:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {return}
self.window = UIWindow(windowScene: windowScene)
self.window!.rootViewController = YourViewController() // Instantiate your UIViewController
self.window!.makeKeyAndVisible()
}
使用objective-c:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
self.window.rootViewController = [[YourViewController alloc] init];
[self.window makeKeyAndVisible];
}
uj5u.com熱心網友回復:
如果您正在開發Xamairn.iOS,這里是示例。
將代碼保留在 中AppDelegate,并將以下代碼添加到SceneDelegate.
[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
UIWindowScene windowScene = scene as UIWindowScene;
Window = new UIWindow(windowScene);
Window.Frame = windowScene.CoordinateSpace.Bounds;
Window.RootViewController = new YourViewController();
Window.MakeKeyAndVisible ();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/454206.html
上一篇:單擊其他地方后如何觸發命令?
