我是iOS新手。我试图使用MWFeedParser构建一个简单的rss阅读器。我没有构建错误,模拟器弹出正常,但模拟器没有显示RSS提要但只显示空白的tableView。 我无法想到出了什么问题。任何帮助将非常感谢。感谢。
// FeedTableViewController.swift
// RssReader
import UIKit
import MWFeedParser
class FeedTableViewController: UITableViewController, MWFeedParserDelegate {
var feedItems = [MWFeedItem]()
func request() {
let url = NSURL(string: "http://feeds.nytimes.com/nyt/rss/Technology")
//creating a feedparser object
let feedParser = MWFeedParser(feedURL: url as URL!)
feedParser?.delegate = self
feedParser?.parse()
}
// MARK: - FEED PARSER DELEGATE
func feedParserDidStart(_ parser: MWFeedParser!) {
feedItems = [MWFeedItem]()
}
func feedParserDidFinish(_ parser: MWFeedParser!) {
self.tableView.reloadData()
}
func feedParser(_ parser: MWFeedParser!, didParseFeedInfo info: MWFeedInfo!) {
print(info)
self.title = info.title
}
func feedParser(_ parser: MWFeedParser!, didParseFeedItem item: MWFeedItem!) {
feedItems.append(item)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
request()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//height for rows
return 100
}
override func numberOfSections(in tableView: UITableView) -> Int {
// return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return the number of rows
return feedItems.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
// Configure the cell...
let item = feedItems[indexPath.row] as MWFeedItem
cell.textLabel?.text = item.title
return cell
}
}