Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序不断崩溃,发现无Swift_Ios_Swift - Fatal编程技术网

Ios 应用程序不断崩溃,发现无Swift

Ios 应用程序不断崩溃,发现无Swift,ios,swift,Ios,Swift,我正在尝试在我的应用程序中显示网络视图。webview的url是对象格式的,因为我是从json获得的。因此,在我的代码中,我将对象转换为NSString并尝试加载视图,但我的应用程序崩溃,原因是:致命错误:在展开可选值时意外发现nil。有没有更好的方法将对象转换为字符串?如何让webview显示url内容 制作详细项目时: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if se

我正在尝试在我的应用程序中显示网络视图。webview的url是对象格式的,因为我是从json获得的。因此,在我的代码中,我将对象转换为NSString并尝试加载视图,但我的应用程序崩溃,原因是:致命错误:在展开可选值时意外发现nil。有没有更好的方法将对象转换为字符串?如何让webview显示url内容

制作详细项目时:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetail" {
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            let object: AnyObject = objectsPath[indexPath.row]
        (segue.destinationViewController as DetailViewController).detailItem = object
        }
    }
}
这是我的密码:

  var detailItem: AnyObject? {
        didSet {
            // Update the view.
            self.configureView()
        }
    }

    func configureView() -> NSURLRequest {
        // Update the user interface for the detail item.
        let detail: AnyObject = self.detailItem!
        let stringURL: String = String(detail as NSString)
        let url = NSURL(string: stringURL)
        let request = NSURLRequest(URL: url!) <---ERROR occurs here
        return request



           // let string:St= detailItem!
          //  previewWebView.
           // println(string)
            //let url = NSURL(string: string)
            //let request = NSURLRequest(URL: url!)
            //self.previewWebView.loadRequest(request)

        }



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.previewWebView.loadRequest(configureView())

    }

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


}
var detailItem:AnyObject?{
迪塞特{
//更新视图。
self.configureView()
}
}
func configureView()->NSURLRequest{
//更新详细信息项的用户界面。
让细节:AnyObject=self.detailItem!
let stringURL:String=String(详细信息为NSString)
让url=NSURL(字符串:stringURL)

让request=NSURLRequest(URL:URL!)在
viewDidLoad()
中调用
configureView()
,而不考虑
self.detailItem
的值。在
viewDidLoad()
中调用此函数之前,应该先检查值,或者应该修改
configureView()
不声明确实存在值
self.detailItem

错误发生在哪里?您在哪里设置
detailItem
?您的
viewDidLoad
正在调用
configureView
,它正在展开
detailItem
,而不检查它是否为
nil
(这里没有设置
detailItem
,所以我希望它是
nil
,并准确地给出这个错误)。此外,除非必须,否则不要使用任何对象。如果
detailItem
a
String
,则只需将其定义为这样,并消除
configureView
中的所有强制转换和转换旋转。我已更新了问题。如果这是tableview的detailpage,则该Matters对象包含字符串数组?是的bjectsPath是一个变化无常的字符串数组。是的,我现在把它自己删除了,愚蠢的错误。哈哈。谢谢你的帮助!