I am trying to create a table view in which it has list of dishes with sections and when we select a row it should go to new table view which consist list of popular restaurants which serves that specific food.
I have created the table view with sections, but my app crashes when I reach at end of the list view. I have added my code below with the snapshot of table view and error.
@IBOutlet weak var dishtable: UITableView!
@IBOutlet weak var namlbl: UILabel!
var Dishes = ["POPULAR Dishes": ["Biryani", "Tandori Chicken","Butter Chicken", "Vada Pav"],"A": ["Aloo baingan", "Aloo ki Tikki", "Amritsari fish"], "B": ["Baigan bharta", "Biryani"]];
override func viewDidLoad() {
super.viewDidLoad()
self.dishtable.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
dishtable.dataSource = self
dishtable.delegate = self
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
let sections:Array<AnyObject> = ["POPULAR Dishes","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
var usernames = [String]()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cellID = "cell"
let cell: UITableViewCell = self.dishtable.dequeueReusableCellWithIdentifier(cellID) as! UITableViewCell
println("value : \(indexPath.section)")
println("value 1: \(indexPath.row)")
cell.textLabel!.text = Dishes[sections[indexPath.section] as! String]![indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
println("Dishes section count : \(section)")
return Dishes.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
return 27
}
func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
}
func tableView(tableView: UITableView,
sectionForSectionIndexTitle title: String,
atIndex index: Int) -> Int{
return index
}
func tableView(tableView: UITableView,
titleForHeaderInSection section: Int) -> String?{
return self.sections[section] as? String
}
This is screenshot for the table view.
This is the screenshot of the error when I scroll down to bottom of the table view.
This is the screenshot of the console for the same error.
Please also let me know how can we add the search feature for the table view.