I am trying to load multiple food menu arrays into one TableViewController. The main menu displays 2 buttons, 1: breakfast menu 2: bakery menu. Every time I press on of them the simulator crashes and shows the SIGABRT error. After a sleepless night of trying it myself I am reaching out to you to have a look at it.... I checked all connections and buttons with segues and it all checks out..
My cell has 3 labels and an image with each their own array. I divided the buttons to select in different content modes. Content mode 1: breakfast & Content mode 2: bakery..
Sorry guys just really want to learn how to do this!
Button Menu Controller:
import UIKit
class foodMenuController: UIViewController {
@IBOutlet weak var mainMenuButton: UIButton!
var contentMode = 0
//Breakfast mode
@IBAction func breakfastButton(sender: AnyObject) {
contentMode == 1
}
//Bakery mode
@IBAction func bakeryButton(sender: AnyObject) {
contentMode = 2
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Hide navigation bar
self.navigationController?.navigationBarHidden = true
func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
TABLEVIEWCONTROLLER
import UIKit
class breakfastFoodControllerTableViewController: UITableViewController {
//Return to Food Menu
@IBOutlet weak var returnButton: UIBarButtonItem!
// BREAKFAST MENU
let breakfastMenu = ["SAVORY CROISSANT", "HEARTY CROISSANT", "LE PETIT DÉJEUNER", "BREAKFAST in AMERICA", "SCRAMBLED EGGS", "FRESH FRUIT BOWL", "OMELETTE", "OATMEAL CUP", "PARIS SANDWICH", "EGGS BENEDICT", "CHEESE BAGEL", "EGGS BALTIQUE", "TOASTED BAGEL", "TOAST"]
// Breakfast menu images
let breakfastMenuImages = ["SAVORY CROISSANT.bmp", "HEARTY CROISSANT.bmp", "LE PETIT DÉJEUNER.bmp", "BREAKFAST in AMERICA.bmp", "SCRAMBLED EGGS.bmp", "FRESH FRUIT BOWL.bmp", "OMELETTE.bmp", "OATMEAL CUP.bmp", "PARIS SANDWICH.bmp", "EGGS BENEDICT.bmp", "CHEESE BAGEL", "EGGS BALTIQUE.bmp", "TOASTED BAGEL.bmp", "TOAST.bmp"]
// Meals definition
let breakfastMealDefined = ["Stuffed with eggs, ham and swiss cheese", "Stuffed with eggs, bacon and swiss cheese", "French baguette with butter, jam", "Two eggs, bacon, sausage, roasted potatoes","Scrambled eggs & smoked salmon","Seasonal fruits with a honey yogurt dressing.","Three fluffy eggs. Add 70 cents per ingredient choice:","Warm oatmeal with milk & extra's","French baguette with ham, cheese & butter","Two poached eggs on an English muffin","Toasted bagel with cream cheese and smoked salmon","Two poached eggs on an English muffin","Toasted bagel with cream cheese & jam","Choose from white, wheat or rye with jelly"]
// Meal price
var breakfastPrice = ["$8,25","$8,25","$7,25","$9,95","$9,25","$5,95","$7,95","$3,95","$9,25","$9,50","$10,25","$11,95","$3,75","$2,75"]
//BAKERY MENU
let bakeryMenu = ["SAVORY CROISSANT", "HEARTY CROISSANT", "LE PETIT DÉJEUNER"]
//Bakery menu images
let bakeryMenuImages = ["SAVORY CROISSANT.bmp", "HEARTY CROISSANT.bmp", "LE PETIT DÉJEUNER.bmp"]
// Bakery definition
let bakeryMealDefined = ["Stuffed with eggs, ham and swiss cheese", "Stuffed with eggs, bacon and swiss cheese", "French baguette with butter, jam"]
// Meal price
var bakeryPrice = ["$8,25","$8,25","$7,25"]
// --> VIEW DID LOAD <-- //
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if foodMenuController().contentMode == 1 {
return breakfastMenu.count
}
if foodMenuController().contentMode == 2 {
return bakeryMenu.count
} else{
return foodMenuController().contentMode; 1
}
}
// CONTENT MODE 1
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! as! firstTableViewSettings
if foodMenuController().contentMode == 1 {
// Cell Configuration (image, text labels, round images)
cell.menuImageOption.image = UIImage (named: breakfastMenu[indexPath.row])
cell.mealPrice.text = breakfastPrice[indexPath.row]
cell.mealDescription.text = breakfastMealDefined[indexPath.row]
cell.menuChoicelabel.text = breakfastMenu[indexPath.row]
cell.menuImageOption.layer.cornerRadius = 30.0
cell.menuImageOption.clipsToBounds = true
}
//CONTENT MODE 2
if foodMenuController().contentMode == 2 {
// Cell Configuration (image, text labels, round images)
cell.menuImageOption.image = UIImage (named: bakeryMenu[indexPath.row])
cell.mealPrice.text = bakeryPrice[indexPath.row]
cell.mealDescription.text = bakeryMealDefined[indexPath.row]
cell.menuChoicelabel.text = bakeryMenu[indexPath.row]
cell.menuImageOption.layer.cornerRadius = 30.0
cell.menuImageOption.clipsToBounds = true
}
return cell
}
}
TABLEVIEWCELL
import UIKit
class firstTableViewSettings: UITableViewCell {
// Outlets for prototype cell configuration
@IBOutlet weak var menuImageOption: UIImageView!
@IBOutlet weak var menuChoicelabel: UILabel!
@IBOutlet weak var mealDescription: UILabel!
@IBOutlet weak var mealPrice: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}