Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';覆盖';只能在类成员上指定-Xcode 9.0,Swift 4_Swift_Uitableview_Overriding_Viewdidload - Fatal编程技术网

';覆盖';只能在类成员上指定-Xcode 9.0,Swift 4

';覆盖';只能在类成员上指定-Xcode 9.0,Swift 4,swift,uitableview,overriding,viewdidload,Swift,Uitableview,Overriding,Viewdidload,我一直收到关于override func的错误消息“'override'只能在类成员上指定”。我尝试在覆盖函数之前插入“}”,但收到了更多错误 import UIKit class MainVC: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableVideo: UITableView! var partyRocks = [Pa

我一直收到关于override func的错误消息“'override'只能在类成员上指定”。我尝试在覆盖函数之前插入“}”,但收到了更多错误

    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
        }

        }

    }
导入UIKit
类MainVC:UIViewController、UITableViewDelegate、UITableViewDataSource{
@IBVAR表格视频:UITableView!
变量PartyRock=[PartyRock]()
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回partyRocks.count
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
tableView.delegate=self
tableView.dataSource=self
如果let cell=tableView.dequeueReusableCell(标识符为“PartyCell”,for:indexPath)为?PartyCell{
让partyRock=partyRock[indexPath.row]
返回单元
}否则{
返回UITableViewCell()
}
重写func viewDidLoad(){
super.viewDidLoad()
}
设p1=PartyRock(imageURL:https://www.lonelyplanet.com/travel-tips-and-articles/eight-amazing-cities-for-street-art/40625c8c-8a11-5710-a052-1479d276ed25,videoURL:,videoTitle:“斯蒂芬的作品”)
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回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()
        }
    }
}
导入UIKit
类MainVC:UIViewController、UITableViewDelegate、UITableViewDataSource{
@IBVAR表格视频:UITableView!
变量PartyRock=[PartyRock]()
设p1=PartyRock(imageURL:https://www.lonelyplanet.com/travel-tips-and-articles/eight-amazing-cities-for-street-art/40625c8c-8a11-5710-a052-1479d276ed25,videoURL:,videoTitle:“斯蒂芬的作品”)
重写func viewDidLoad(){
super.viewDidLoad()
}
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回partyRocks.count
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
tableView.delegate=self
tableView.dataSource=self
如果let cell=tableView.dequeueReusableCell(标识符为“PartyCell”,for:indexPath)为?PartyCell{
让partyRock=partyRock[indexPath.row]
返回单元
}否则{
返回UITableViewCell()
}
}
}

还要注意,在viewcontroller中复制了两次
numberofrowsinsection
方法时,您会遇到问题,因此我删除了一个…

如果您正确缩进了程序,问题会变得很明显。