gpt4 book ai didi

json - swift:无法使用存储的属性 'tableView' 覆盖

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

<分区>

我有下面的代码:

import UIKit

class SearchTableViewController: UITableViewController, UISearchBarDelegate{

final let urlString = "http://tvshowapi.azurewebsites.net/tvshownewsfeed"

@IBOutlet var tableView: UITableView!

var nameArray = [String]()
var favouriteCountArray = [String]()
var imgURLArray = [String]()

override func viewDidLoad() {
super.viewDidLoad()

createSearchBar()

self.downloadJsonWithURL()

}

func createSearchBar() {
let searchBar = UISearchBar()
searchBar.showsCancelButton = false
searchBar.placeholder = "Search a show"
searchBar.delegate = self
searchBar.backgroundColor = UIColor.black
searchBar.barTintColor = UIColor.black
self.navigationItem.titleView = searchBar
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = UIColor.black

let searchTextField: UITextField? = searchBar.value(forKey: "searchField") as? UITextField

searchTextField?.textAlignment = NSTextAlignment.left
}

func downloadJsonWithURL() {
let url = NSURL(string: urlString)
URLSession.shared.dataTask(with: (url as? URL)!, completionHandler: {(data, response, error) -> Void in
if let jsonObj = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [[String:Any]] {

for tvshow in jsonObj! {
if let name = tvshow["screenName"] as? String {
self.nameArray.append(name)
}
if let cnt = tvshow["favouriteCount"] as? Int {
self.favouriteCountArray.append("\(cnt)")
}
if let image = tvshow["imageUrl"] as? String {
self.imgURLArray.append(image)
}
}


OperationQueue.main.addOperation({
self.tableView.reloadData()
})
}
}).resume()
}

func downloadJsonWithTask() {

let url = NSURL(string: urlString)

var downloadTask = URLRequest(url: (url as? URL)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 20)

downloadTask.httpMethod = "GET"

URLSession.shared.dataTask(with: downloadTask, completionHandler: {(data, response, error) -> Void in

let jsonData = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments)

print(jsonData!)

}).resume()
}

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

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return nameArray.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! SearchTableViewCell
cell.nameLabel.text = nameArray[indexPath.row]
cell.dobLabel.text = favouriteCountArray[indexPath.row]

let imgURL = NSURL(string: imgURLArray[indexPath.row])

if imgURL != nil {
let data = NSData(contentsOf: (imgURL as? URL)!)
cell.imgView.image = UIImage(data: data as! Data)
}

return cell
}


}

Xcode 出现三个错误:

  1. 不能用存储属性“tableView”覆盖
  2. 使用 Objective-C 选择器“tableView”的“tableView”的 getter 与具有相同 Objective-C 选择器的父类(super class)“UITableViewController”的“tableView”的 getter 冲突
  3. 使用 Objective-C 选择器“setTableView:”的“tableView” setter 与具有相同 Objective-C 选择器的父类(super class)“UITableViewController”中的“tableView” setter 冲突

SearchTableViewController以下是 TableViewCell 的代码

class SearchTableViewCell: UITableViewCell {

@IBOutlet weak var imgView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var dobLabel: UILabel!


override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

我做错了什么?

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