Unrecognized selector sent to instance 0x7feca9469620 2016-05-10 19:34:58.781 TribeA2[76123:4834825] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TribeA2.RegisterPageViewController registerButtonTapped:]: unrecognized selector sent to instance 0x7feca9469620'
Terminating with uncaught exception of type NSException
.
import UIKit
class RegisterPageViewController: UIViewController {
@IBOutlet weak var userFirstNameTextField: UITextField!
@IBOutlet weak var userLastNameTextField: UITextField!
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
var databasePath = NSString()
override func viewDidLoad() {
super.viewDidLoad()
let filemgr = NSFileManager.defaultManager()
let dirPaths =
NSSearchPathForDirectoriesInDomains(.DocumentDirectory,
.UserDomainMask, true)
let docsDir = dirPaths[0]
databasePath = (docsDir as NSString).stringByAppendingPathComponent(
"users.db")
if !filemgr.fileExistsAtPath(databasePath as String) {
let userDB = PersonDatabase(path: databasePath as String)
if userDB == nil {
print("Error: \(userDB.lastErrorMessage())")
}
if userDB.open() {
let sql_stmt = "CREATE TABLE IF NOT EXISTS USERS (ID INTEGER PRIMARY KEY AUTOINCREMENT, FNAME TEXT, LNAME TEXT, EMAIL TEXT, PASSWORD TEXT)"
if !userDB.executeStatements(sql_stmt) {
print("Error: \(userDB.lastErrorMessage())")
}
userDB.close()
} else {
print("Error: \(userDB.lastErrorMessage())")
}
}
}
@IBAction func saveData(sender: AnyObject) {
let userDB = PersonDatabase(path: databasePath as String)
if userDB.open() {
func displayMyAlertMessage(userMessage:String)
{
let myAlert = UIAlertController(title:"Alert", message:
userMessage, preferredStyle:
UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title:"Ok", style:
UIAlertActionStyle.Default, handler:nil)
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated:true,
completion:nil)
}
let insertSQL = "INSERT INTO USERS (fname, lname, email, password) VALUES ('\(userFirstNameTextField.text)', '\(userLastNameTextField.text)' '\(userEmailTextField.text)', '\(userPasswordTextField.text)')"
let result = userDB.executeUpdate(insertSQL, withArgumentsInArray: nil)
if !result {
displayMyAlertMessage("All fields are required")
print("Error: \(userDB.lastErrorMessage())")
return
} else {
displayMyAlertMessage("Thank you for registering \(userFirstNameTextField.text)")
}
}