【问题标题】:Loading RSS Feed to IOS Swift将 RSS 提要加载到 IOS Swift
【发布时间】:2019-02-08 07:56:48
【问题描述】:

我正在尝试将 RSS 提要加载到 IOS 应用程序。浏览了相当多的教程,找到了以下内容,但它引发了异常。

来源:https://github.com/tichise/TIFeedParser

 func loadRSS() {

        let feedUrlString:String = "https://news.google.com/news?hl=us&ned=us&ie=UTF-8&oe=UTF-8&output=rss"

        Alamofire.request(feedUrlString).response { response in

            if let data = response.data, let _ = String(data: data, encoding: .utf8) {

                TIFeedParser.parseRSS(xmlData: data as NSData, completionHandler: {(isSuccess, channel, error) -> Void in

                    if (isSuccess) {
                        self.items = channel!.items!
                        self.videoTableView.reloadData()//Exception on this line
                    }

                    if (response.error != nil) {
                        print((response.error?.localizedDescription)! as String)
                    }
                })
            }
        }

    }

异常是线程 1:致命错误:在展开可选值时意外发现 nil

我做错了什么?如果是这样参考或如何解决?将非常有帮助!

【问题讨论】:

    标签: ios swift uitableview exception rss-reader


    【解决方案1】:

    你需要使用if let来避免异常:

    if let allItems = channel.items {
           self.items = allItems
           self.videoTableView.reloadData()//Exception on this line
    }
    

    我也可以运行你的项目,请检查下面的模拟器 图片:

    【讨论】:

    • 请检查您的 videoTableView,我认为您的表格视图为零
    • @MRDR 我可以运行你的项目。请检查我的更新答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2013-10-15
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 2016-08-28
    相关资源
    最近更新 更多