我的新 ViewController 出现 SIGABRT 错误?
My New ViewController is giving SIGABRT error?
我有许多不同的按钮,例如 UIStepper 和 DatePicker 以及 MapView。谁能帮我让我的整个视图控制器和按钮正常工作。我一直收到关于 SIGABRT 的错误。它说的是 "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Field_Service_Report.AddController hoursStepper:]: unrecognized selector sent to instance 0x7fb5d7c8d010'"
这是我的视图控制器代码:
import UIKit
import MapKit
import CoreLocation
class AddController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var hoursStepperResult: UILabel!
@IBOutlet weak var hoursStepper: UIStepper!
@IBOutlet weak var minutesStepperResult: UILabel!
@IBOutlet weak var minutesStepper: UIStepper!
@IBOutlet weak var currentLocationLabel: UILabel!
@IBOutlet weak var dateOfReport: UIDatePicker!
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Start Map Contents
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
// End Map Contents
}
// Start Stepper Contents
@IBAction func hoursStepperAction(_ sender: UIStepper) {
hoursStepperResult.text = String(Int(sender.value))
}
@IBAction func minutesStepperAction(_ sender: UIStepper) {
minutesStepperResult.text = String(Int(sender.value))
}
// End Stepper Contents
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// Here is the new code its giving me 3 erroe because im trying to get the text and numbers from another ViewController to print out in this VC.
@IBAction func doneACButton(_ sender: AnyObject) {
let newVC = storyboard?.instantiateViewController(withIdentifier: "ResultController") as! ResultController
newVC.intPassed = hoursIntProvided
newVC.intPassed = minutesIntProvided
newVC.stringPassed = resultedHours.text!
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Errors: " + error.localizedDescription)
}
// MARK: - Navigation
}
注意方法签名中的冒号:
-[Field_Service_Report.AddController hoursStepper:]
^
这是采用参数的方法的签名,而不是访问器的签名。您确定您没有在某处拼错选择器名称或在 IB 中意外连接了一些本应删除的内容吗? (也许如果你重命名了一个方法而忘记重做动作连接?)
我有许多不同的按钮,例如 UIStepper 和 DatePicker 以及 MapView。谁能帮我让我的整个视图控制器和按钮正常工作。我一直收到关于 SIGABRT 的错误。它说的是 "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Field_Service_Report.AddController hoursStepper:]: unrecognized selector sent to instance 0x7fb5d7c8d010'"
这是我的视图控制器代码:
import UIKit
import MapKit
import CoreLocation
class AddController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var hoursStepperResult: UILabel!
@IBOutlet weak var hoursStepper: UIStepper!
@IBOutlet weak var minutesStepperResult: UILabel!
@IBOutlet weak var minutesStepper: UIStepper!
@IBOutlet weak var currentLocationLabel: UILabel!
@IBOutlet weak var dateOfReport: UIDatePicker!
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Start Map Contents
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
// End Map Contents
}
// Start Stepper Contents
@IBAction func hoursStepperAction(_ sender: UIStepper) {
hoursStepperResult.text = String(Int(sender.value))
}
@IBAction func minutesStepperAction(_ sender: UIStepper) {
minutesStepperResult.text = String(Int(sender.value))
}
// End Stepper Contents
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// Here is the new code its giving me 3 erroe because im trying to get the text and numbers from another ViewController to print out in this VC.
@IBAction func doneACButton(_ sender: AnyObject) {
let newVC = storyboard?.instantiateViewController(withIdentifier: "ResultController") as! ResultController
newVC.intPassed = hoursIntProvided
newVC.intPassed = minutesIntProvided
newVC.stringPassed = resultedHours.text!
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Errors: " + error.localizedDescription)
}
// MARK: - Navigation
}
注意方法签名中的冒号:
-[Field_Service_Report.AddController hoursStepper:]
^
这是采用参数的方法的签名,而不是访问器的签名。您确定您没有在某处拼错选择器名称或在 IB 中意外连接了一些本应删除的内容吗? (也许如果你重命名了一个方法而忘记重做动作连接?)