gpt4 book ai didi

ios - 如何以编程方式以模态方式呈现 View Controller ?

转载 作者:IT王子 更新时间:2023-10-29 08:21:51 26 4
gpt4 key购买 nike

编辑:在解决这个问题时,我发现从您的 UITabBarController 开始,然后通过您的AppDelegate.mdidFinishLaunchingWithOptions: 方法。

问题:此代码在我的 AppDelegate.m 中的 application didFinishLaunchingWithOptions: 方法中

if([result isEqualToString: @"log"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
[(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
NSLog(@"It's hitting log");
}

它只是为正在登录的用户 获取 HTTP 响应,并将它们带到我的 TabBarController。问题在于它使用推送 而不是模态 转换来显示页面。由于 presentModalViewController 方法在 iOS7 中已被弃用或删除,我如何以编程方式强制显示模态?

编辑: )

最佳答案

swift

这是在不引用导航 Controller 的情况下在 Swift 中执行此操作的方法:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondViewController = storyboard.instantiateViewController(withIdentifier: "secondViewController") as! SecondViewController
self.present(secondViewController, animated: true, completion: nil)

根据需要更改 Storyboard名称、 View Controller 和 ID。

另见 how to dismiss a view controller programmatically .

关于ios - 如何以编程方式以模态方式呈现 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20893505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com