I'm trying to create an app where the user clicks a button on the first page and it goes to another page with a table on it. But when I click that button, all that comes up is an error:
libc++abi.dylib: terminating with uncaught exception of type NSException
and a Thread 1: Signal SIGABRT on this line in AppDelegate.swift:
class AppDelegate: UIResponder, UIApplicationDelegate {
Help?
First view controller - the one with the button (ViewController):
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var textGifteeName: UITextField!
@IBOutlet weak var pickerAge: UIPickerView!
var age = String()
let itemsAge: [String] = ["1960", "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"]
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return itemsAge.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return itemsAge[row]
}
func pickerView(_ pickerView: UIPickerView , didSelectRow row: Int, inComponent component: Int) {
age = itemsAge[row]
}
@IBOutlet weak var labelGifteeLocationsPreview: UILabel!
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
That's all other information the user puts in, which all act fine. I have the button on the storyboard, I did not put it in the code of ViewController.
Here's the view controller with the table (LocationsTableController):
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var tableLocations: UITableView!
let itemsLocations: [String] = ["Pacific Northwest", "West Coast", "The West", "Midwest", "Great Lakes", "The South", "New England"]
var locationsPreviewtext = [String]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemsLocations.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellLocations: UITableViewCell = UITableViewCell()
cellLocations.textLabel?.text = itemsLocations[indexPath.row]
return cellLocations
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
locationsPreviewtext.append(itemsLocations[indexPath.row])
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
if locationsPreviewtext.isEmpty {
return
} else {
let ind = index(ofAccessibilityElement: locationsPreviewtext[indexPath.row])
print(ind)
if ind == NSNotFound {
print(locationsPreviewtext[indexPath.row])
print(ind)
locationsPreviewtext.remove(at: indexPath.row)
}
}
}