我正在尝试创建一个应用,用户点击第一页上的按钮,然后转到另一个带有表格的页面。但是当我点击那个按钮时,所有出现的都是错误:
libc++abi.dylib: terminating with uncaught exception of type NSException
和一个线程1:在AppDelegate.swift中的这一行发出信号SIGABRT:
class AppDelegate: UIResponder, UIApplicationDelegate {
帮助?
第一个视图控制器 - 带按钮的那个(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()
}
用户输入的所有其他信息,一切正常。 我在故事板上有按钮,我没有把它放在ViewController的代码中。
这里是带有表(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)
}
}
}