-2

I keep receiving the error message "'override' can only be specified on class members" in regards to the override func. I have tried inserting a "}" before the override func but received even more errors.

    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
        }

        }

    }
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

This shall rid you of the override error - some weird brace usage perhaps caused by inaccurate cut and pasting of your tableview methods...

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()
        }
    }
}

Also beware you will encounter problems as you duplicated the numberofrowsinsection method twice in your viewcontroller so I deleted one...

Louis Leung
  • 508
  • 4
  • 11