- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的基于 Storyboard 的应用具有以下结构:
NavigationController (NavCa) —> CollectionViewController (VCa) —> 模态呈现 —> TabBarController (TabBarC)
TabBarC 有两个选项卡,每个都嵌入在自己的 NavigationController 中:
TabBar[0] NavigationController (NavCTab0) —> TableViewController (VC01) —> ViewController (VC02) —> ViewController (VC03)
TabBar[1] NavigationController (NavCTab1) —> ViewController (VC11) —> ViewController (VC12)
我的问题:我的 3D QuickAction 之一必须直接导航到 VC01。
我确实浏览了该网站。话题Swift: Programmatically transitioning from 1 view to another via a TabBar and Navigation Controller看起来很接近我的。我尝试了代码(AppDelegate.swift 中的快速操作处理程序):
let mainSB = UIStoryboard(name: "Main", bundle: nil)
let tbc = mainSB.instantiateViewController(withIdentifier: “TabBarC”) as? TabBarController
tbc?.selectedIndex = 0
let ncTab0 = tbc?.viewControllers![0] as! UINavigationController
let vc01 = mainSB.instantiateViewController(withIdentifier: “VC01”) as! TableViewController01
let vc02 = mainSB.instantiateViewController(withIdentifier: “VC02”) as! ViewController02
let vc03 = mainSB.instantiateViewController(withIdentifier: “VC03”) as! ViewController03
let arrayOfVC = [vc01, vc02, vc03]
ncTab0.setViewControllers(arrayOfVC, animated: false)
ncTab0.popToViewController(vc01, animated: true)
self.window?.rootViewController?.present(tbc, animated: true, completion: nil)
但什么也没发生。输出窗口中没有任何内容。应用程序没有任何反应(如果应用程序被终止,它会开始到 VCa 屏幕;如果应用程序没有被终止,它会停留在快速操作之前的位置)。
非常感谢任何帮助。
附言我只会说 SWIFT。
编辑
带有快速操作处理程序的我的 AppDelegate.swift:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var isLaunchedFromQuickAction = false
// Check if it's launched from Quick Action
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
isLaunchedFromQuickAction = true
_ = handleQuickAction(shortcutItem)
}
// Return false if the app was launched from a shortcut, so performAction... will not be called.
return !isLaunchedFromQuickAction
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
completionHandler(handleQuickAction(shortcutItem))
}
func handleQuickAction(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
var quickActionHandled = false
let type = shortcutItem.type.components(separatedBy: ".").last!
if type == "QuickAction1" {
... // Navigating to VC01, see piece of code above
quickActionHandled = true
}
}
return quickActionHandled
}
我在其他应用中使用的相同快速操作处理程序。该应用程序的结构为 NavigationController --> ViewController1 --> ViewController2 --> ViewController3。还有一个快速操作导航到 ViewController2。它就像一个魅力。与新应用程序的唯一区别是应用程序结构。我无法通过所有这些 TabBarControllers、NavigationControllers 等赢得导航...
编辑 2
按照建议,我尝试了 Apple 示例代码 (https://developer.apple.com/library/content/samplecode/ApplicationShortcuts/Introduction/Intro.html#//apple_ref/doc/uid/TP40016545-Intro-DontLinkElementID_2) 中的另一种快速操作处理方法。而且...现在可以使用了。部分。
如果我终止应用程序,3D 快速操作会完美运行。
但是。如果我不终止应用程序并且只在后台发送它 - 快速操作不起作用并且在控制台中我收到相同的旧消息:'警告:尝试在
有什么想法吗?
编辑 3
最终解决方案。
3D Quick Action 与 Apple 示例代码 (https://developer.apple.com/library/content/samplecode/ApplicationShortcuts/Introduction/Intro.html#//apple_ref/doc/uid/TP40016545-Intro-DontLinkElementID_2) 中的完全相同
case ShortcutIdentifier.first.type:
// Handle shortcut 1 (static).
let mainSB = UIStoryboard(name: "Main", bundle: nil)
let tbc = mainSB.instantiateViewController(withIdentifier: "TabBarC") as? TabBarController
self.window?.rootViewController?.dismiss(animated: true, completion: nil)
self.window?.rootViewController?.present(tbc!, animated: true, completion: nil)
handled = true
break
此代码经过测试并有效。
最佳答案
根据我对你的代码的理解,我认为只有三行代码就足够了
let mainSB = UIStoryboard(name: "Main", bundle: nil)
let tbc = mainSB.instantiateViewController(withIdentifier: “TabBarC”) as? TabBarController
self.window?.rootViewController.present(tbc, animated: true, completion: nil)
因为标签栏 View Controller 似乎只在 Storyboard 中设置。默认选中tabbar Controller的第一个tab。
编辑
“attempt to present ....”问题的其他解决方案您可以设置标志,并在 View Controller viewDidLoad 方法中尝试以与代码相同的方式呈现 tabBarViewController。
关于ios - 通过 NavigationController-TabBarController-NavigationController 以编程方式导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48255056/
您好,所以我有这个 storyboard 结构 我在 ViewController B 中有一个 button 我需要那个 button 指向底部NavigationController 其中有 Vi
我的基于 Storyboard 的应用具有以下结构: NavigationController (NavCa) —> CollectionViewController (VCa) —> 模态呈现 —>
我可以用 MyFirstAppDelegate *delegate = (MyFirstAppDelegate *)[[UIApplication sharedApplication] delegat
我正在使用以下策略构建一个基于窗口的(所有 UI 都以编程方式连接,没有 IB)MonoTouch 应用程序: 伪代码: Note: I'm not calling base.ViewDidLoad
我发现了困难的方法 navigationController.navigationBarHidden = NO; 和 navigationController.navigationBar.hidden
这两种说法有什么区别。为了隐藏导航栏,我使用以下语句之一在 viewWillAppear 方法中隐藏导航栏,如下所示: -(void)viewWillAppear:(BOOL)animated {
我已经发布了这个问题,但这次我发布了代码。所以我有一个uiviewController,在这个viewController的viewDidLoad中我隐藏了navigationController的b
我想在横向显示另一个没有选项卡栏的 View 。所以我创建了一个新 View ,只更改 self.view 和 self.hidesBottomBarWhenPushed = YES; 但这对我不起作
当我将新的 ViewController 推送到导航 Controller 堆栈上时,“后退”按钮是前一个 Controller 的标题。 如何将后退按钮中的文本更改为“后退”而不是默认的最后一个 C
我在我的应用程序中设置了一个 subview “弹出窗口”,如果用户点击 subview 弹出窗口上的按钮,我想显示一个 navController。到目前为止,我已经设置了按钮,但是如果我点击按钮,
我有两个问题: 问题 1:我正在尝试更改导航后退按钮,我正在从父 ViewController 执行此操作: -(void)prepareForSegue:(UIStoryboardSegue *)s
我有一个 UINavigationController,它的根 Controller (UITableViewController) 和一个 UIViewController 的实例,当我单击导航 C
我正在尝试制作我的第一个基于表格的应用程序。但是它不会改变导航栏上标题的颜色。 我试过这段代码,但它似乎不起作用: this.NavigationController.NavigationItem.T
问题如图所示。我怎样才能从 viewcontroller C 返回到 A。方法 popViewController Animated 不起作用。 最佳答案 您的 Controller 层次结构存在问题
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit th
我在使用 Navigation Controller 转到我的详细 View 时遇到问题。 我正在使用 tableview 来显示一些练习,当你点击练习时,你会进入详细 View ,嵌入在导航 Con
我试图通过允许用户添加算命应用程序的新结果来理解演示 View Controller 。当用户点击导航栏右上角的“添加新结果”时,会弹出一个新的 View Controller ,用户可以在此处输入新
当我点击页面底部的灰色按钮时,我想使用 popToRootController 从最后一页返回到第一页。 我不明白如何同时对两个导航 Controller 进行操作。我为最后两页使用了一个库。 Sid
我有一个 navigationController 嵌入在我的 Root View 和 subview 中,并且在我的一个 subview 中有: @IBAction func button(send
是否可以将后退按钮的图标从箭头更改为其他图标? (在导航栏中) 我在storyboard的preferences里没找到解决方案 最佳答案 如果您的部署目标至少是 iOS 7,您可以使用 backIn
我是一名优秀的程序员,十分优秀!