import UIKit
class ToDoViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var DateLabel: UILabel!
@IBOutlet weak var MonthLabel: UILabel!
@IBOutlet weak var DayLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var newButton: UIImageView!
static var ToDoEvents:[event] = []
override func viewDidLoad() {
super.viewDidLoad()
ToDoViewController.readFromFile()
let nib = UINib(nibName: "CustomCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "customCell")
}
public static func readFromFile(){
ToDoViewController.ToDoEvents.append(event(eventName: "Spanish Workbook", eventLength: 3601, complete: false))
ToDoViewController.ToDoEvents.append(event(eventName: "History Test", eventLength: 37, complete: false))
ToDoViewController.ToDoEvents.append(event(eventName: "Lit Essay", eventLength: 40, complete: false))
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return ToDoViewController.ToDoEvents.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomCell
let currentEvent = ToDoViewController.ToDoEvents[indexPath.row]
let eventName = currentEvent.name!
let eventLength = currentEvent.time!
let completion = currentEvent.isComplete!
print(eventName)
print(eventLength)
print(completion)
cell.customInit(name: "\(eventName)", time: "\(eventLength)", completed: completion)
return cell
}
}
Currently, I am trying to create an app with a ToDo list. I am using a UITableView to display the information, and I have a custom UITableViewCell called "CustomCell" that I am using to display the information in the table view. However, when I run this code, there is nothing showing up on the screen. I also added some print statements in the CellForRowAtIndexPath method, and those print statements are not getting executed. Then I tried to add
self.tableView.delegate = self
self.tableView.dataSource = self
however, when I try to run the app with this additional code, the app crashes giving the following error:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason:
'Could not load NIB in
bundle: 'NSBundle
</Users/sid/Library/Developer/CoreSimulator
/Devices/812843C0-ABBA-43E9-A391-
0BED3CBB5030/data/Containers/Bundle
/Application/F8DABFF7-80ED-49E1-8760-315C3C99AFB1/TimeIt.app>
(loaded)' with name 'CustomCell''
I have also watched multiple tutorials that outline how to go about adding a custom cell to your code, and none of these tutorials use the tableView.delegate = self or the tableView.dataSource = self code.
I am not sure what I am doing wrong. All help is appreciated
Thank You in advance!