首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >注册不工作-分析-斯威夫特2

注册不工作-分析-斯威夫特2
EN

Stack Overflow用户
提问于 2015-12-08 13:51:17
回答 1查看 58关注 0票数 0

当我在输入用户名和密码后点击我的“注册”按钮,我的应用程序就会崩溃。我对这种编程很陌生,我不知道为什么。这是我的错误:

代码语言:javascript
复制
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

这是我注册行动的代码:

代码语言:javascript
复制
@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()
            }



        })



        }

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 14:33:12

重命名您的方法

代码语言:javascript
复制
@IBAction func SignUpAction(sender: AnyObject){

代码语言:javascript
复制
@IBAction func SignUp(sender: AnyObject){

为了防止像这样的崩溃,您应该仔细阅读错误消息,它说:

-Scoop.CustomSignUpViewController SignUp::未识别的选择器被发送到实例..。

这意味着您试图在视图控制器上调用一个不存在的方法。如果您拼写错误的方法名称(您发送了SignUp名称,但在您的视图控制器SignUpAction),则经常会发生这种情况。

顺便说一句,根据指导方针,最好用小写字符来命名方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34157633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档