Reputation: 83
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)")
}
}
Upvotes: 0
Views: 843
Reputation: 11039
In the interface builder if you right-click on that button, a popup will be shown where you can see that you have "action" connected with name -registerButtonTapped:
to your class, but actually you haven't implemented that method (or you deleted it for some reason). So you must delete that connection by clicking on x button in that popup either implement -registerButtonTapped:
method.
Upvotes: 1
Reputation: 404
If you right click the button,the button will show the action or variables which are associated.please check that if it is available in your controller
Upvotes: 0
Reputation: 82759
in RegisterPageViewController
you were created the registerButtonTapped
button action, but button method not implemented, if you are not used the registerButtonTapped
delete from attribute inspector, else implenent the button action on class like the following
func registerButtonTapped(sender: UIButton)
{
}
Upvotes: 2