我的活动指标没有出现

时间:2015-04-20 21:37:13

标签: swift activity-indicator

我想在用户输入登录凭据并单击登录按钮后显示活动指示符。这似乎是直截了当的,但是当我跑步时,指示器没有显示(构建成功)。我不确定这是不是因为当应用程序运行真实时,它会将凭据传递给服务器进行验证但该代码尚未激活,因此登录是即时的,或者如果我写错了但不是导致错误。谢谢你的帮助。

 @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中,以获取我为测试代码而创建的按钮。它适用于按钮。

1 个答案:

答案 0 :(得分:0)

您的代码很好或者说我会说它有效,因为提到的是因为这个过程需要几毫秒而不能持久,我建议您在代码中添加断点因此,当您按Build时,可以查看代码中的步骤的交互。