简体   繁体   中英

SIGABRT when tapping button

I have a simple app right now and I have a button called "Load", and I have the following lines. Every time I run it, I tap the load button to load the details, and when I do, it seems to freeze and cause SIGABRT in thread 1, then brings up the AppDelegate file. How can I prevent this? What's wrong?

Edit: I have narrowed it down to the method itself, for when I made it so it uses the method without the button in ViewDidLoad it causes the exception before I hit anything. Still, why?

loadButton.target = self
loadButton.action = "getMovieDetails:353"

And the function getMovieDetails

// REST Request to get movie details
func getMovieDetails(movieID: Int) {
    let url: NSURL = NSURL(string: "http://yts.re/api/movie.json?id=\(movieID)")
    var request: NSMutableURLRequest = NSMutableURLRequest()
    request.URL = url
    request.HTTPMethod = "GET"

    NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
        var error: AutoreleasingUnsafePointer<NSError?> = nil
        let json: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary

        if json {
            let movieTitleClean: AnyObject! = json["MovieTitleClean"]
            self.navigationItem.title = "\(movieTitleClean)"
        } else {
            self.navigationItem.title = "Error title"
        }


        })
}

And the only changed made to appDelegate were in the first method

application.setStatusBarHidden(false, animated: false)
application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

You're selector is invalid for the loadButton.action. You cannot give arguments at the end, as you did with 353 . When the button is touched, the parameter will be the button itself, so you should have a function with the following signature:

func handleLoadButtonTouch(loadButton: UIButton) { ... }

Then, set the action as follows:

loadButton.action = "handleLoadButtonTouch:" // note, the ':' is a weird artifact from Obj-C, which simply means 1 argument lives there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM