rocket101
rocket101

Reputation: 7537

Dismissing Modal View Swift

EDIT: Thanks to the person behind the answer below, who fixed the unknown class. However, can anyone tell me if the code to dismiss is correct? I am on vacation and can't program until I get back.

I am developing an app in Swift. Currently, I am working on an info screen (legal notices, credits, documentation, etc) that will be presented modally atop the main screen.

The expected behavior is that, when a button press triggers Dismiss in InfoViewController, the modal view controller is dismissed.

Here’s the code I’m trying to use:

//This is InfoViewController, the swift file used to conorol the info screen.

import UIKit

class InfoViewController: UIViewController {

    @IBAction func Dismiss(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: {});//This is intended to dismiss the Info sceen.
        println("pressed")
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

}

Here’s the layout of the storyboards:

postimg.org/image/wbozsmtr3/

When I press the button, the app crashes and doesn’t dismiss the modal view controller.

It compiles, suggesting it is not a syntactual error.

Here’s the LLVM debugger output:

2014-08-30 20:02:20.571 CryptoCalc[799:244086] 17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize=13.000000 //Unrelated stuff deleted. 2014-08-30 20:03:03.756 CryptoCalc[799:244086] Unknown class InfoViewController in Interface Builder file. 2014-08-30 20:03:20.485 CryptoCalc[799:244086] -[UIViewController Dismiss:]: unrecognized selector sent to instance 0x14d57990 2014-08-30 20:03:20.489 CryptoCalc[799:244086] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController Dismiss:]: unrecognized selector sent to instance 0x14d57990' * First throw call stack: (0x2238be2f 0x2f46bc8b 0x22391179 0x2238f097 0x222c11f8 0x259b9fef 0x259b9f91 0x259a4d13 0x259b99fd 0x259b96d7 0x259b2fa1 0x25989a09 0x25bfbae3 0x259884a1 0x2235257f 0x2235198f 0x2234fff5 0x2229e611 0x2229e423 0x297f80a9 0x259e8485 0x73720 0x7375c 0x2f9f1aaf) libc++abi.dylib: terminating with uncaught exception of type NSException

If you need any more info, let me know. Thanks so much.

Upvotes: 3

Views: 12699

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40624

The main issue here is Unknown class InfoViewController in Interface Builder file.

You need to make sure that (in 'Custom Class' section)

1) The class in the storyboard is set to InfoViewController

2) The module is set to 'Current - your project name'

screen shot include to show which part of Interface builder I am referring to

enter image description here

Upvotes: 3

Related Questions