I made basic tableView
inside ViewController
and while loading I get
fatal error: unexpectedly found nil while unwrapping an Optional value
Which points to tableView.delegate = self
(by points to I mean this line is highlighted in green colour in Xcode). Here's full code:import UIKit
import UIKit
class FAQViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UINavigationControllerDelegate, SWRevealViewControllerDelegate {
@IBOutlet var menuButton: UIBarButtonItem!
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
if revealViewController() != nil {
//I have SWRevealController that slides viewController from Left side
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("FAQ") as! FAQTableViewCell
cell.questionLabel.text = "Here goes Question"
cell.answearLabel.text = "This is answear"
return cell
}
}
From what I can see from your example, you look to be setting things up using a storyboard, but since the class is a UIViewController and not a UITableViewController, I think your connections are not wired up correctly.
I would check in the debugger to make sure tableView is not nil and to check in the storyboard to make sure that the connections look OK.
You can also wire up the tableViews dataSource and delegate in storyboard by right clicking on the tableView, and then dragging from the circle across from dataSource or delegate to the view controller associated with your storyboard scene (i.e. the first icon in the hierarchy right below the scene name in the storyboard file).
Happy to clarify if this does not make sense...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With