Conform to protocol in ViewController, in Swift Conform to protocol in ViewController, in Swift ios ios

Conform to protocol in ViewController, in Swift


You use a comma:

class GameList: UIViewController, UITableViewDelegate, UITableViewDataSource {    // ...}

But realize that the super class must be the first item in the comma separated list.

If you do not adopt all of the required methods of the protocol there will be a compiler error. You must get all of the required methods!


As XCode6-Beta7 releases,

I noticed the protocol method of UITableViewDataSource changed a little bit and sounded the same conform to protocol error which worked fine in beta6.

These are the required methods to be implemented according to the UITableViewDataSource protocol:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // insert code}func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // insert code}

You might want to re-check the difference or re-implement the delegate method that you thought you just implement.


You must implement two require methods here:

func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {    return 10}func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")    cell.text = "Row #\(indexPath.row)"    cell.detailTextLabel.text = "Subtitle #\(indexPath.row)"    return cell}


matomo