Я отправляю данные через контроллеры представления, используя навигационный центр.Но я хочу использовать эти данные внутри кнопки, но переменная не распознается.
Это то, что не распознается.
class ViewController10: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(forName: ID_TRANSFER, object: nil, queue: nil){ notification in
if let object = notification.object as? [String: Any] {
if let currentid = object["UserID"] as? Int {
print(currentid, "crap it works")
}
}
}
enterPrice1.delegate = self
enterBrand.delegate = self
enterProduct1.delegate = self
enterComment.delegate = self
var fileUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("RateappDatabase4.sqlite")
if sqlite3_open(fileUrl.path, &db) != SQLITE_OK{
print("Error opening database")
print(fileUrl = try!
FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("RateappDatabase4.sqlite"))
}
if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS Rate (RateID INTEGER PRIMARY KEY AUTOINCREMENT, rating INTEGER, UserID INTEGER, ProductId INTEGER, PostID INTEGER)", nil, nil, nil) != SQLITE_OK {
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error creating table: \(errmsg)")
}
if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS Product (ProductID INTEGER PRIMARY KEY AUTOINCREMENT, product TEXT, UserID INTEGER, brand TEXT, price INTEGER, PostID INTEGER)", nil, nil, nil) != SQLITE_OK {
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error creating table: \(errmsg)")
}
if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS Comment (CommentID INTEGER PRIMARY KEY AUTOINCREMENT, comment TEXT, UserID INTEGER, orderCom INTEGER, PostID INTEGER)", nil, nil, nil) != SQLITE_OK {
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error creating table: \(errmsg)")
}
if sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS Post (PostID INTEGER PRIMARY KEY AUTOINCREMENT, ProductID INTEGER, UserID INTEGER, RateID INTEGER, CommentID INTEGER, Post TEXT)", nil, nil, nil) != SQLITE_OK {
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error creating table: \(errmsg)")
} // Do any additional setup after loading the view.
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.allowsEditing = false
}
@IBOutlet weak var enterPrice1: UITextField!
@IBOutlet weak var enterComment: UITextField!
@IBOutlet weak var enterBrand: UITextField!
@IBOutlet weak var enterProduct1: UITextField!
@IBAction func lipstick1(_ sender: Any) {
var stmt: OpaquePointer?
let queryString3 = "INSERT INTO Rate (rating, UserID) VALUES (?, ?)"
let lipstickValue1 = 1
if sqlite3_prepare(db, queryString3, -1, &stmt, nil) != SQLITE_OK{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("error preparing insert: \(errmsg)")
return
}
if sqlite3_bind_int(stmt, 1, Int32(lipstickValue1)) != SQLITE_OK{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("failure inserting lipstick1: \(errmsg)")
return
}
if sqlite3_bind_int(stmt, 2, Int32(currentid)) != SQLITE_OK{
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("failure inserting lipstick1: \(errmsg)")
return
}
if sqlite3_step(stmt) != SQLITE_DONE {
let errmsg = String(cString: sqlite3_errmsg(db)!)
print("failure binding lipstick1: \(errmsg)")
return
}
print("rating of 1")
}
}