我不断收到的问候倍率FUNC“只能在类成员指定的‘覆盖’”的错误消息。我试图插入一个“}”在覆盖前FUNC却收到甚至更多的错误。
import UIKit
class MainVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableVideo: UITableView!
var partyRocks = [PartyRock]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return partyRocks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.delegate = self
tableView.dataSource = self
if let cell = tableView.dequeueReusableCell(withIdentifier: "PartyCell", for: indexPath) as? PartyCell {
let partyRock = partyRocks[indexPath.row]
return cell
} else {
return UITableViewCell()
}
override func viewDidLoad() {
super.viewDidLoad()
}
let p1 = PartyRock(imageURL: "https://www.lonelyplanet.com/travel-tips-and-articles/eight-amazing-cities-for-street-art/40625c8c-8a11-5710-a052-1479d276ed25", videoURL: "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/9f31OCHXAsI\" frameborder=\"0\" allowfullscreen></iframe>", videoTitle: "Stephen's Artwork")
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return partyRocks.count
}
}
}
这应摆脱你倍率错误的 - 一些奇怪的大括号的使用也许是你的tableview方法不准确的剪裁和粘贴引起...
import UIKit
class MainVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableVideo: UITableView!
var partyRocks = [PartyRock]()
let p1 = PartyRock(imageURL: "https://www.lonelyplanet.com/travel-tips-and-articles/eight-amazing-cities-for-street-art/40625c8c-8a11-5710-a052-1479d276ed25", videoURL: "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/9f31OCHXAsI\" frameborder=\"0\" allowfullscreen></iframe>", videoTitle: "Stephen's Artwork")
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return partyRocks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.delegate = self
tableView.dataSource = self
if let cell = tableView.dequeueReusableCell(withIdentifier: "PartyCell", for: indexPath) as? PartyCell {
let partyRock = partyRocks[indexPath.row]
return cell
} else {
return UITableViewCell()
}
}
}
另外注意的是你在你的ViewController复制的numberofrowsinsection
方法两次,你会遇到的问题,所以我删除了一个...