当我输入用户名和密码后点击我的“注册”按钮时,我的应用程序崩溃了。我是这类编程的新手,我不知道为什么。这是我的错误:
2015-12-08 08:37:51.477 Scoop[835:19495] -[Scoop.CustomSignUpViewController SignUp:]: unrecognized selector sent to instance 0x7fa383cc8220
2015-12-08 08:37:51.484 Scoop[835:19495] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Scoop.CustomSignUpViewController SignUp:]: unrecognized selector sent to instance 0x7fa383cc8220'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108960f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a684deb objc_exception_throw + 48
2 CoreFoundation 0x000000010896956d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001088b6eea ___forwarding___ + 970
4 CoreFoundation 0x00000001088b6a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010917ee91 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x00000001092ea4d8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001092ea7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x00000001092e98d4 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x00000001091eced1 -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x00000001091edc06 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010919d2fa -[UIApplication sendEvent:] + 263
12 UIKit 0x0000000109177abf _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010888d011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000108882f3c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x00000001088823f3 __CFRunLoopRun + 867
16 CoreFoundation 0x0000000108881e08 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010bdd0ad2 GSEventRunModal + 161
18 UIKit 0x000000010917d30d UIApplicationMain + 171
19 Scoop 0x00000001075e463d main + 109
20 libdyld.dylib 0x000000010b19692d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我的注册操作代码:
@IBAction func SignUpAction(sender: AnyObject) {
var username = self.usernameField.text
var password = self.passwordField.text
var confirmPassword = self.confirmPasswordField.text
if (username?.characters.count > 4 || password?.characters.count > 5){
var alert = UIAlertView(title: "Oops!", message: "Username must be
greater than 4 & password must be greater than 5.", delegate: self,
cancelButtonTitle: "Okay")
alert.show()
}else if (password?.characters.count !=
confirmPassword?.characters.count){
var alert = UIAlertView(title: "Oops!", message: "Your passwords do
not match. Try again.", delegate: self, cancelButtonTitle: "Okay")
alert.show()
}else {
self.actInd.startAnimating()
var newUser = PFUser()
newUser.username = username
newUser.password = password
newUser.signUpInBackgroundWithBlock({ (succeed, error) -> Void in
self.actInd.stopAnimating()
if ((error) != nil) {
var alert = UIAlertView(title: "Error", message: "\(error)",
delegate: self, cancelButtonTitle: "Okay")
alert.show()
}else {
var alert = UIAlertView(title: "Success!", message: "You
have been signed up for Scoop!", delegate: self, cancelButtonTitle:
"Okay")
alert.show()
}
})
}
}
答案 0 :(得分:2)
重命名您的方法
@IBAction func SignUpAction(sender: AnyObject){
到
@IBAction func SignUp(sender: AnyObject){
为了防止这样的崩溃,你应该仔细阅读错误信息,它说:
- [Scoop.CustomSignUpViewController SignUp:]:无法识别的选择器发送到实例...
这意味着您尝试在视图控制器上调用一个不存在的方法。通常情况下,如果您拼错了方法名称(您发送了SignUp
名称,但在视图控制器中SignUpAction
)
顺便说一下,根据指南,更好的方法是命名以小写字符开头的方法。