gpt4 book ai didi

ios - 在 ViewController 和 tableView 上拉动刷新

转载 作者:行者123 更新时间:2023-11-28 06:15:14 27 4
gpt4 key购买 nike

<分区>

我想拉动刷新我的 RSS 提要新闻应用程序。我使用 View Controller 和 UITableView。在 View Controller 上应该怎么做?我们应该添加什么?我的代码在这里。

import UIKit

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,XMLParserDelegate {
@IBOutlet weak var tblView: UITableView!

var parser = XMLParser()
var news = NSMutableArray()
var elements = NSMutableDictionary()
var element = NSString()
var title1 = NSMutableString()
var link = NSMutableString()
var desc = NSMutableString()


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
parsingDataFromURL()
addNavBarImage()
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}




func parsingDataFromURL()
{
news = []
parser = XMLParser(contentsOf: URL(string: "feedurl")!)!
parser.delegate = self
parser.parse()
tblView.reloadData()
}


func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {

element = elementName as NSString

if(elementName as NSString) .isEqual(to: "item")
{
elements = NSMutableDictionary()
elements = [:]
title1 = NSMutableString()
title1 = " "
link = NSMutableString()
link = " "
}
}

func parser(_ parser: XMLParser, foundCharacters string: String) {

if element .isEqual(to: "title")
{
title1.append(string)
}
else if element.isEqual(to: "description")
{
desc.append(string)
}
else if element.isEqual(to: "link")
{
link.append(string)
}
}


func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
if (elementName as NSString) .isEqual(to: "item")
{
if !title1 .isEqual(nil)

{
elements.setObject(title1, forKey: "title" as NSCopying)
}

if !link .isEqual(nil)
{
elements.setObject(link, forKey: "link" as NSCopying)
}
if !desc.isEqual(nil)
{
elements.setObject(desc, forKey: "description" as NSCopying)
}


news.add(elements)
}
}


internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return news.count
}

internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCell(withIdentifier: "myCell")! as UITableViewCell

if (cell.isEqual(NSNull.self))
{
cell = Bundle.main.loadNibNamed("myCell", owner: self, options: nil)?[0] as! UITableViewCell
}

cell.textLabel?.text = (news.object(at: indexPath.row) as AnyObject).value(forKey: "title") as! NSString as String

cell.detailTextLabel?.text = (news.object(at: indexPath.row) as AnyObject).value(forKey: "link") as! NSString as String

return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

{
tableView.deselectRow(at: indexPath, animated: true)
let newsdetailVC = storyboard?.instantiateViewController(withIdentifier: "NewsDetailViewController") as! NewsDetailViewController
newsdetailVC.selectedTitle = (news.object(at: indexPath.row) as AnyObject).value(forKey: "title") as! NSString as String
newsdetailVC.selectedUrl = (news.object(at: indexPath.row) as AnyObject).value(forKey: "link") as! NSString as String

self.navigationController?.pushViewController(newsdetailVC, animated: true)
}
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com