0
votes

The app that I am working on has a UITableViewController embedded in a UINavigationController. Tapping on cells in the UITableViewController presents other UIViewControllers. I am trying to implement 3D touch in an iOS app so that the user can directly access one of the UIViewControllers from the home screen. Everything works fine except that when I tap on the link on the home screen, I get a black screen (except for the navigation bar). Here is the relevant code from the AppDelegate:

func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
    var handled = false
    guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else { return false }
    guard let shortCutType = shortcutItem.type as String? else { return false }

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    var vc = UIViewController()
    switch (shortCutType) {
    case ShortcutIdentifier.Tables.type:
        vc = storyboard.instantiateViewController(withIdentifier: "TableVC") as! StatTableViewController
        handled = true
        break
    case ShortcutIdentifier.ChiSquare.type:
        vc = storyboard.instantiateViewController(withIdentifier: "Chisquare") as! CSViewController
        handled = true
        break
    case ShortcutIdentifier.PowerContinuous.type:
        vc = storyboard.instantiateViewController(withIdentifier: "PowerCont") as! PowerContViewController
        handled = true
        break
    case ShortcutIdentifier.PowerDichotomous.type:
        vc = storyboard.instantiateViewController(withIdentifier: "PowerDichot") as! PowerDichotViewController
        handled = true
        break
    default:
        break
    }
    let navVC = self.window?.rootViewController as! UINavigationController
    navVC.pushViewController(vc, animated: true)
    //        navVC.show(vc, sender: self)  // Same result

    return handled
}

I'm reasonably sure that I'm getting to the correct UIViewController each time, but the screen is black. I can navigate back to the UITableViewController, where I can then segue back to the UIViewController and it works just fine. So it is clearly something in the presentation of the window that is messed up.

Thanks in advance for any and all advice.

1
It might be not getting data to show on the screen. check your data source using break point.Prema Janoti
In the UIViewController you open, can you debug and check what all methods get called by either using break points or adding UIAlertView. Does viewDidLoad get called? Does viewDidAppear? What is happening inside the opened UIViewController?Rikh
As far as I can tell none of the lifecycle methods get called in the UIViewController that is presented from the AppDelegate. I put breaks in viewDidLoad in all 6 of them just in case they were mis-targeted. Also, when the UIViewControllers are accessed via segue from the UITableViewController, all the lifecycle methods are called.Glenn

1 Answers

0
votes

The problem turned out to be in my info.plist file. I had mistakenly thought that $(PRODUCT_BUNDLE_IDENTIFIER) as a prefix for the UIApplicationShortcutItemType would be my bundle identifier. It wasn't, so replacing $(PRODUCT_BUNDLE_IDENTIFIER) with my explicit bundle identifier did the trick.

Thanks for the comments, which eventually led to my finding the answer.