简体   繁体   English

在iOS中,继续收到“在解包可选值时意外发现nil”的致命错误

[英]Keep getting a fatal error that says “unexpectedly found nil while unwrapping an Optional value” in iOS

I run my code on Xcode and it build fine but when I tap a button to change views it crashes with this error. 我在Xcode上运行我的代码并且它构建正常但是当我点击一个按钮来更改视图时它会因此错误而崩溃。

var selectedAccount : ACAccount!
var tweets : NSMutableArray?
var imageCache : NSCache?
var queue : NSOperationQueue?

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationItem.title = selectedAccount.accountDescription

    queue = NSOperationQueue()
    queue!.maxConcurrentOperationCount = 4

    func retrieveTweets() {
        tweets?.removeAllObjects()

        if let account = selectedAccount {
            let requestURL = NSURL(string: "https://api.twitter.com/1.1/statuses/home_timeline.json")

            let request = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: SLRequestMethod.GET, URL: requestURL, parameters: nil)

            request.account = account
            request.performRequestWithHandler()
                {
                    responseData, urlResponse, error in

                    if(urlResponse.statusCode == 200)
                    {
                        var jsonParseError : NSError?
                        self.tweets = NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.MutableContainers, error: &jsonParseError) as? NSMutableArray
                    }

                    dispatch_async(dispatch_get_main_queue()) {
                        self.tableView.reloadData()
                    }
            }
        }
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    // Return the number of rows in the section.

    if let tweetCount = self.tweets?.count {
        return tweetCount
    }
    else
    {
        return 0
    }
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("TweetCell", forIndexPath: indexPath) as TweetCell

    return cell
}

When it crashes it it posts an green line over the line "self.navigationItem.title = selectedAccount.accountDescription" 当它崩溃时,它会在“self.navigationItem.title = selectedAccount.accountDescription”行上发布一条绿线。

I'm not sure why its saying its associated with this line. 我不确定为什么它说它与这条线有关。

Please help 请帮忙

SC SC

Make sure you remove any warning messages here. 请务必在此处删除任何警告消息。

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不断出现致命错误:解开Optional值时意外发现nil - Keep getting fatal error: unexpectedly found nil while unwrapping an Optional value Swift-Keep收到“致命错误:解开可选值时意外发现nil” - Swift-Keep getting “fatal error: unexpectedly found nil while unwrapping an Optional value” 它在tableview的cellforrowatindexpath中崩溃,表示:“致命错误:在展开可选值时意外发现nil” - It crashes in cellforrowatindexpath of tableview , says : “fatal error: unexpectedly found nil while unwrapping an Optional value” 致命错误:在Tableview中展开Optional值时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value in Tableview 致命错误:解开可选值(lldb)时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) 快速致命错误:解开Optional值时意外发现nil - swift fatal error: unexpectedly found nil while unwrapping an Optional value Swift致命错误:解开Optional值时意外发现nil - Swift fatal error: unexpectedly found nil while unwrapping an Optional value 致命错误:展开一个可选值(lldb)时意外发现nil - Fatal error: Unexpectedly found nil while unwrapping an Optional value (lldb) UIToolbar的“致命错误:解开可选值时意外发现为零” - 'fatal error: unexpectedly found nil while unwrapping an Optional value' for UIToolbar 致命错误:在 UITableViewCell 中解包可选值时意外发现 nil - fatal error: unexpectedly found nil while unwrapping an Optional value in UITableViewCell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM