【问题标题】:My activity indicator is not appearing我的活动指示器没有出现
【发布时间】:2015-04-20 21:37:12
【问题描述】:

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

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

【问题讨论】:

    标签: swift activity-indicator


    【解决方案1】:

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

    【讨论】:

    • 谢谢。首先让我说这是我的第一个应用程序,所以我正在学习一切。我把断点放进去,在我建立之后,我点击登录按钮。然后我被带回 Xcode,窗口的左下角塞满了东西。你能帮我弄清楚那是什么或给我指个参考吗?我什至不知道如何提问,因为这对我来说都很陌生(除了我的变量)。
    • 恭喜你,你必须首先通过改变其内容和进程结果来确定显示空间的底部,然后在蓝色指示器中确定为活动断点,即使在此右侧你可能会观察到几个箭头您可能只对第一个实例 Step into 感兴趣,这将允许您从应用程序继续进行 Debug,直到它在另一个断点处停止。
    • 我建议在更改删除activityIndicator 的操作之前放置一个断点来满足条件验证的用户数据和另一个更明确地要求他创建另一个问题的操作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    相关资源
    最近更新 更多