Search code examples
iosanimationclosuresibactionswift2

In IBAction: "arguments passed to call that takes no arguments"


enter image description here

From what I've seen, the best way to resolve this error:

arguments passed to call that takes no arguments

will be to use

do {try ...} and catch {...}

However, it seems impossible to implement it in this code!

@IBAction func onTapButton(sender: AnyObject) {

    btnFromNib.animate(1, completion: { () -> () in

        var myTabbarController = self.storyboard?.instantiateInitialViewController("myTabbarController") as! UITabBarController
        var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.window?.rootViewController = myTabbarController

        myTabbarController.transitioningDelegate = self

        self.presentViewController(myTabbarController, animated: true, completion: nil)
    })

}

Solution

  • You're trying to instantiate a view controller with an identifier parameter, but you're not using the right method for this.

    You should use instantiateViewControllerWithIdentifier instead of instantiateInitialViewController.

    Reference: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStoryboard_Class/index.html#//apple_ref/occ/instm/UIStoryboard/instantiateViewControllerWithIdentifier:

    Instantiates and returns the view controller with the specified identifier.

    You use this method to create view controller objects that you want to manipulate and present programmatically in your application. Before you can use this method to retrieve a view controller, you must explicitly tag it with an appropriate identifier string in Interface Builder.

    This method creates a new instance of the specified view controller each time you call it.