iOS : 'MyViewController' does not conform to protocol 'UITableViewDataSource'

ios 13 download
ios meaning
ios download
ios 14
ios 13 download link
ios 12
ios 13 iphone 6
ios full form
  • I am new to IOS swift development. I used to work with previous Xcode 6 beta.

  • I have downloaded the Xcode 6.0.1 and I can not get this to work Xcode Version: 6.0.1

  • I am still getting "'MyViewController' does not confirm to protocol 'UITableViewDataSource' " when I try to run the example.

Can someone please help me? I have gone through other issues on this site and added all the required functions for "UITableViewDataSource";


import UIKit
import Foundation

class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{

var array1:[String] = ["one","two","three","four"]

    var array2:[String] = ["IOS","Android","java","c++","Swift"]

    let sectionCount = 2

    var myTableView:UITableView!

    //    init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    //        var rect = CGRectMake(0, 0, 220, 320)
    //        myTableView = UITableView(frame: rect, style: UITableViewStyle.Grouped)
    //        super.init(nibName: nil, bundle: nil)
    //        // Custom initialization
    //    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var rect = CGRectMake(0, 0, 320, 600)
        myTableView = UITableView(frame: rect, style: UITableViewStyle.Grouped)
        myTableView!.delegate = self
        myTableView!.dataSource = self
        self.view.addSubview(myTableView)

    }

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


    //dataSourrce
    //tableview:tableview,section:
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
        switch section{
        case 0:
            return array1.count
        case 1:
            return array2.count
        default:
            return 1
        }

    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        //func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{

        //---cellstart----
        let identifier = "identifier"
        //        var cell:UITableViewCell
        //cell
        var cell = tableView.dequeueReusableCellWithIdentifier(identifier) as? MyCell
        if cell == nil {
            //            cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: identifier)
            cell = MyCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: identifier)
        }
        //---cellend----

        switch indexPath.section{
        case 0:
            //            cell!.textLabel.text = array1[indexPath.row]
            cell!.myLable!.text = array1[indexPath.row]
        case 1:
            //            cell!.textLabel.text = array2[indexPath.row]
            cell!.myLable!.text = array2[indexPath.row]
        default:
            println()
        }
        var image = UIImage(named: "images/qq.png")
        //        cell!.imageView.image = image
        cell!.myImageView!.image = image
        //        cell!.detailTextLabel.text = "\(indexPath.section)\(indexPath.row)
        return cell!
    }

  //dataSourrce
    func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
        return sectionCount
    }

    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        var title:String? = nil
        switch section {
        case 0:
            title = "Num"
        case 1:
            title = "Prog"
        default:
            title = nil
        }
        return title
    }

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
        println("Test\(indexPath.section) \(indexPath.row)")
    }


    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 60.0
    }



    func numberOfComponentsInPickerView(pickerView: UIPickerView!) -> Int {}

    func pickerView(pickerView: UIPickerView!,numberOfRowsInComponent component: Int) -> Int{}

    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?{
    }

    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?{
    }

}

***************** My Cell Class ***********************************

import Foundation
import UIKit

class MyCell: UITableViewCell {

    let indetifier:String = "indetifier"


    var myLable:UILabel?


    var myImageView:UIImageView?

        override init(style: UITableViewCellStyle, reuseIdentifier: String!)
        {
        super.init(style: .Subtitle, reuseIdentifier: indetifier)

        var rect = CGRectMake(10, 0, 60, 30)
        self.myLable = UILabel()
        self.myLable!.frame = rect
        self.myLable!.textColor = UIColor.redColor()
        self.contentView.addSubview(self.myLable!)

        var imageRect = CGRectMake(160, 10, 40, 40)
        self.myImageView = UIImageView()
        self.myImageView!.frame = imageRect
        self.contentView.addSubview(self.myImageView!)


    }

        required init(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
}

You need to look at the whole error message. This specific message includes additional information about which methods are missing:

Type 'MyViewController' does not conform to protocol 'UITableViewDataSource'
Protocol requires function 'tableView(_:numberOfRowsInSection:)' with type '(UITableView, numberOfRowsInSection: Int) -> Int'
Candidate has non-matching type '(UITableView!, numberOfRowsInSection: Int) -> Int'

So... your numberOfRowsInSection takes an optional UITableView, and should take a required UITableView (this is a change they made between 6 and 6.1, all UITableView delegate and datasource methods now take required tableView and indexPath values)

Microsoft’s new Family Safety app is now available to preview on Android and iOS, Microsoft Family Safety app comes to Android and iOS in early beta Looking for online definition of IOS or what IOS stands for? IOS is listed in the World's largest and most authoritative dictionary database of abbreviations and acronyms IOS - What does IOS stand for?

Try this simple solution:

import UIKit

class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{
    //MARK: - Life Cycle
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    //MARK: - Tableview Delegate & Datasource
    func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
    {
        return 10
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int
    {
        return 1
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {

        let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {

    }

}

Microsoft Family Safety app comes to Android and iOS in early beta, Instagram iOS update brings bulk comment deleting, control for who can mention or tag you Browse and download apps to your iPad, iPhone, or iPod touch from the App Store. The App Store has more than one million apps and games for your iOS device.

class ROTableView: UITableView, UITableViewDelegate {

    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
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    }
}

When you create the subclass for UITableView please refer the above code, you will not get any error.

Instagram iOS update brings bulk comment deleting, control for who can mention or tag you, Find out how your apps can take advantage of the latest features in iOS on iPhone and iPad. iOS 11.3.1. iOS 11.3.1 improves the security of your iPhone or iPad and addresses an issue where touch input was unresponsive on some iPhone 8 devices because they were serviced with non-genuine replacement displays. Note: Non-genuine replacement displays may have compromised visual quality and may fail to work correctly.

In my case, i named my UITableView as tableView. That caused this same error:

'MyViewController' does not conform to protocol 'UITableViewDataSource'

including another error:

Candidate is not a function

And changed tableview name to something else, error is gone.

iOS 13, iOS is Apple's mobile operating system that runs on iPhone, iPad, and iPod touch​. Historically, Apple releases a new iOS version once a year,  iOS 11.2.5 is a maintenance release for iPhone, iPad, and iPod touch users though it’s a little bit larger than your standard bug fix release. It comes with a mixture of bug fixes, patches, and yes, some new features. In this guide we’ll take you through the most important things to know, right now,

iOS, iOS is an operating system for mobile devices ,such as smartphones and tablets, developed by Apple. It is custom built and exclusive to Apple's iPhone, iPad,  That will be iOS 11.3 and it is the big one. iOS 11.3 brings the detailed battery diagnostics and clarity users have deserved ever since the shutdown debacle began well over a year ago, and which

iOS - News, Features, Compatible Devices, Rumors, etc, Everything about iOS is designed to be easy. That includes switching to it. With just a few steps, you can migrate your content automatically and securely from  Apple has released the final version of iOS 11.2.5 for compatible iPhone, iPad and iPod users around the world. Here's what is new and how to download it. iOS 11.2.5 is Now Available for Download.

iOS, Apple iOS is a proprietary mobile operating system that runs on mobile devices such as the iPhone, iPad and iPod Touch. Apple iOS is based on the Mac OS X  Download current and previous versions of Apple's iOS, iPadOS, watchOS, tvOS and audioOS firmware and receive notifications when new firmwares are released. 1 Choose a product. 2 Choose a platform. 3 Choose a version. iPhone iPad iPod touch Apple TV HomePod Apple Watch. Follow @iOSReleases Telegram Bot r/jailbreak.

Comments
  • In your numberOfRowsInSection method (and pretty much all your other delegate/datasource methods), UITableView shouldn't be an implicitly unwrapped optional. This changed at some point between Xcode releases. You should keep up to date on the changes by reading the release notes with each new version.
  • Hi Sorry, I am not sure what you mean by "UITableView shouldn't be an implicitly unwrapped optional." would you be able to correct the above code if possible ?
  • Please see page 83 of Apple's book on Swift. Optionals are an elemental part of the language and you need to understand how they work.
  • Hi There, I am not understanding "Optionals are an elemental part" on page 83 :(.
  • His point is that optionals are a very important part of Swift that you must know and understand before you can use the language. Especially when integrating with Objective-C. You need to go back and read and understand the whole book.
  • Thank you so much!