Pages

Basic errors to counter if using Table View

1.) Unable to dequeue a cell with identifier:--> This is the very basic error that will occur in your project. It occurs basically due to the reason that you forgot to register a class of cells that you are using to display in the table view. Well it's not like you are foolish enough to forget about using the method shown below...

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell1", forIndexPath: indexPath) as? UITableViewCell        
cell?.textLabel?.text = finalUrl[indexPath.row]
return cell!
}

But even if Xcode is still showing this error then you will have to register a class by using below shown function:

"tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell1")"

In this function all you are doing is registering the class of cells you are using to display in the table view with a certain Identifier. Thats all now if you recompile your project you will not get any error.


2.) Table View doesn't confirm to the protocol UITableViewDataSource:--> This error Xcode begin to show as soon you declare your class implements DataSource protocols.  Here is the figure to show that error:


This is the error basically shown by Xcode because you did't implement two "required" functions declared in Data Source protocols. These two functions are...

a.)func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
b.)func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {}

All other functions are optional types. Weather you use them or not its up to you. Here is the figure:
As you can see in the figure that first two functions are required functions && other are marked with "optional" keyword.