我正在制作搜索系统。 如果在文本字段中输入文本并且其值在数据库中,则它将转换到下一个屏幕并显示所获取的数据。 在调试屏幕上,由于显示获取的值,我认为API正在运行。但是,我收到EXC_BAD_INSTRUCTION错误(代码= EXC_I386_INVOP,子代码= 0x0) 这个错误导致我被困5个小时。请告诉我。 谢谢。
configure -static -qtlibinfix MyInFix -debug-and-release -prefix “C:\Qt\Static\5.7.0” -platform win32-msvc2015 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -qt-sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests
导入UIKit class ResultViewController:UIViewController {
SearchViewController
import UIKit
import Alamofire
class SearchViewController: UIViewController {
//API
let SEARCH_CODE = "API URL"
//devaultUserValue
let defaultValues = UserDefaults.standard
@IBOutlet weak var searchCodeFeild: UITextField!
@IBOutlet weak var labelMessage: UILabel!
@IBAction func searchBtn(_ sender: UIButton) {
//Getting device code
let parameters: Parameters=[
"deviceCode" : searchCodeFeild.text!
]
//making post request
Alamofire.request(SEARCH_CODE, method: .post, parameters: parameters).responseJSON
{
response in
//printing response
print(response)
//getting the json value from the server
if let result = response.result.value{
let jsonData = result as! NSDictionary
//if there is no error
if(!(jsonData.value(forKey: "error")as! Bool)){
let device = jsonData.value(forKey: "device") as! NSDictionary
//getting user value
let deviceID = device.value(forKey: "id") as! Int
let deviceName = device.value(forKey: "name") as! String
let deviceCode = device.value(forKey: "deviceCode") as! String
self.defaultValues.set(deviceID, forKey: "id")
self.defaultValues.set(deviceName, forKey: "name")
self.defaultValues.set(deviceCode, forKey: "deviceCode")
let resultViewController = self.storyboard?.instantiateViewController(withIdentifier: "resultViewController") as! ResultViewController
self.navigationController?.pushViewController(resultViewController, animated: true)
self.dismiss(animated: false, completion: nil)
}else{
self.labelMessage.text = "Sorry not find device"
}
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}