You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UIButton的@IBAction函数未被识别,点击无响应问题求助

调查APP按钮点击无响应问题排查
  • 正在开发一款带调查功能的APP,需求是用户选择多选题选项后点击Next按钮,将答案同步到Firebase Firestore。但目前点击按钮后完全没反应,就连测试用的print("button pressed method accessed")都不输出,怀疑是视图控制器出了问题。
  • 试过在同一个视图控制器里新建一个只有print语句的空白按钮,点击后同样没有输出。已经检查过Next按钮和代码的连线、函数名及segue的拼写,也试过删除按钮重新连线、清理Build文件夹,问题依然存在。
  • 现在就算isBtnSelected为true,点击Next按钮还是没任何反应,测试打印语句完全不执行。以下是我的@IBAction代码:
@IBAction func nextTapped(_ sender: Any) {
        if isbtnSelected == true {
            print("button pressed method accessed")
            UserData.shared.years = Int((self.currentButton.titleLabel?.text)!)!
            
            if let user = Auth.auth().currentUser {
                let userPreferencesCollectionRef = Firestore.firestore().collection("user_preferences")
                let userDocumentRef = userPreferencesCollectionRef.document(user.uid)
                
                var questionData: [String: Any] = [:]
                questionData["years"] = UserData.shared.years

                userDocumentRef.setData(questionData, merge: true) { error in
                    if let error = error {
                        print("Error setting preferences: \(error.localizedDescription)")
                    } else {
                        print("Preferences set successfully!")
                        self.performSegue(withIdentifier: "nextQues", sender: self)
                    }
                }
            }
        }
        else {
            let alert = UIAlertController(title: "Error", message: "Please select an answer", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: NSLocalizedString("Okay", comment: "Close alert"), style: .default))
            self.present(alert, animated: true, completion: nil)
            return
        }
    }
  • 在多个位置设置断点后,发现有错误阻止performSegue执行,但Debug控制台没有任何打印信息,没法定位错误来源。

内容的提问来源于stack exchange,提问作者mariaj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:52:11