簡體   English   中英

從函數內部訪問常量或變量到`viewdidload`中以保存在Firebase Swift 3中

[英]Access constant or variables from inside a function to in `viewdidload` to save in firebase swift 3

我無法訪問在函數內部定義的常量或變量,例如,當我選擇一行時,現在我在didselectrow函數中定義了一個常量,該常量的值在控制台中打印,但現在我想將該值保存在firebase因此當我在button調用該值時,為什么不明確? 我該怎么辦?

這是我在button編寫的代碼,未定義常數countryGroup 因為我已經在didselectrow定義了它

按鍵

 @IBAction func createAccountAction(_ sender: Any) {
 ref.child("user_registration").child(UserID!).setValue(["username": fullName.text, "email": emailTextField.text, "contact": numberText.text, "city": myCity.text, "state": countryText.text, "country": country])
}

didselectrow

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if tableView == tableViewB {

        let   selectedData = dropDownList[indexPath.row]

        buttonB.setTitle(selectedData, for: .normal)


        self.tableViewB.isHidden = true
        self.flag = 1

        let indexPath = tableViewB.indexPathForSelectedRow

        let currentCell = tableViewB.cellForRow(at: indexPath!)! as UITableViewCell
        let country = currentCell.textLabel!.text!
        print("\(country)")
    }

代替定義let country = currentCell.textLabel!.text! didselectrow我定義了一個全局變量var country = String? 並將country = currentCell.textLabel!.text!設置country = currentCell.textLabel!.text!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM