0

我想在用户输入登录凭据并单击登录按钮后显示活动指示器。这看起来很简单,但是当我运行(构建成功)时指示器没有显示。我不确定这是否是因为当应用程序真正运行时,它会将凭据传递给服务器进行验证,但该代码尚未激活,所以登录是即时的,或者我写错了但没有导致错误。感谢您的帮助。

 @IBAction func loginButtonTapped(sender: AnyObject) {

    //add error checking for loginEntered and passwordEntered if they are blank
    if loginEntered.text == "" || passwordEntered.text == "" {

        //Define the variable error for the message that should be displayed
        self.alertError = "Please enter your Login ID and/or Password"

    }

    if self.alertError != ""  { //if there is an error with the login

        //Display the error message on screen
        self.displayAlert("Missing Required Information", error: alertError)

        //reset error variable
        self.alertError = ""

        //return the user to the LoginID field and empty it if there is data in it. Empty the password field too.  ?? How do I do that??

    } else { //the login ID and password are entered

        //setup for a spinner to notify the user the app is working on something
        activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 80, 80))
        activityIndicator.center = self.view.center;
        activityIndicator.backgroundColor = (UIColor(white: 0.3, alpha: 0.5)) //creates a background behind the spinner
        activityIndicator.layer.cornerRadius = 10
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        UIApplication.sharedApplication().beginIgnoringInteractionEvents()

该代码基于登录凭据和从服务器返回的数据继续执行多个 if 语句。最后,停止忽略交互事件。最后,我将相同的代码放入 IBAction 中,用于我为测试代码而创建的按钮。它适用于按钮。

4

1 回答 1

0

您的代码很好,或者我会说它可以工作,因为提到的是因为该过程需要毫秒而不是持久性,我建议您在代码中放置断点,以便在按下 Build 时可以查看代码中步骤的交互。

于 2015-04-20T22:03:52.930 回答