UITableViewController delegate gives error in swift

I am getting below error while generating simple code for UITableView in Swift Xcode 6.1

/Users/classic/Documents/CIPL/Demo Projects/DemoTableView/DemoTableView/ViewController.swift:11:1: Type 'ViewController' does not conform to protocol 'UITableViewDataSource'

/Users/classic/Documents/CIPL/Demo Projects/DemoTableView/UIKit.UITableViewDataSource:3:48: Protocol requires function 'tableView(_:cellForRowAtIndexPath:)' with type '(UITableView, cellForRowAtIndexPath: NSIndexPath) -> UITableViewCell'

      

Does anyone know why this problem occurs?

+3


source to share


2 answers


Have you declared the required UITableVIewDataSource protocol functions in your class?



func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int

// Row display. Implementers should *always* try to reuse cells by setting each cell reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

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

      

0


source


You must implement all of the required protocol method for the tableview.



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

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arrayData.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Define your cell and return it
}

      

0


source







All Articles