は認識されないセレクターをインスタンスに0x7feca9469620 2016年5月10日 19を送信58.781 TribeA2 [76123:4834825] *** キャッチされない例外 'NSInvalidArgumentException' による終了アプリ理由: - タイプ
NSException
のキャッチされない例外で終了スイフトプロジェクトNSException
'[TribeA2.RegisterPageViewController registerButtonTappedは:] 未認識セレクタインスタンス0x7feca9469620に送ら'。
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)")
}
}