我的 activity 指标没有出现

My activity indicator is not appearing

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

 @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 中以测试代码。它适用于按钮。

你的代码很好或者我会说它有效,因为提到这个过程需要几毫秒并且不是持久的,我建议你放置断点 在您的代码中,以便在您按下构建时可以查看代码中步骤的交互。