gpt4 book ai didi

ios - 使用未解析的标识符 'displayAlertMessage'

转载 作者:行者123 更新时间:2023-11-30 11:59:59 25 4
gpt4 key购买 nike

我尝试稍微移动一下代码。我得到的错误是在声明之前使用了局部变量 displayMessage 。因此,我将 func displayAlertMessage 移至显示警报消息注释上方,新错误是 use of unresolvedidentifier 'displayAlertMessage'

//
// RegisterPageViewController.swift
// UserLoginandRegistration
//
// Created by Iyah Chulo on 17/11/2017.
// Copyright © 2017 Iyah Chulo. All rights reserved.
//

import UIKit

class RegisterPageViewController: UIViewController {

@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var ReenterPasswordTextField: UITextField!



override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func RegisterButtonTapped(_ sender: Any) {

let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
let userReenterPassword = ReenterPasswordTextField.text;

// Check for empty fields
if((userEmail?.isEmpty)! || (userPassword?.isEmpty)! ||
(userReenterPassword?.isEmpty)!)

{

func displayAlertMessage(userMessage: String) { let myAlert = UIAlertController(title:"Alert", message: userMessage, preferredStyle:
UIAlertControllerStyle.alert);

let okAction = UIAlertAction(title:"Ok", style:
UIAlertActionStyle.default, handler:nil)

myAlert.addAction(okAction);

self.present(myAlert, animated: true,
completion:nil)
}

//显示警报信息 displayAlertMessage(userMessage: "所有字段均为必填") 返回; }

        //Check if passwords match
if(userPassword != userReenterPassword)
{

// Display an alert message

displayAlertMessage(userMessage: "Passwords do not match")

return;

}


// Store data

UserDefaults.standard.set(userEmail, forKey:"userEmail")
UserDefaults.standard.set(userEmail, forKey:"userPassword")
UserDefaults.standard.synchronize()

// Display alert message with confirmation
var myAlert = UIAlertController(title:"Alert", message: "Registration is successful.Thank you!", preferredStyle:
UIAlertControllerStyle.alert);
let okAction = UIAlertAction(title:"Ok", style:
UIAlertActionStyle.default) { action in
self.dismiss(animated: true, completion:nil)

}








}

}

最佳答案

您的 displayAlertMessage 函数定义需要位于类中其他函数之外。

另外,请注意 Swift 不需要分号!

试试这个:

import UIKit

class RegisterPageViewController: UIViewController {

@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var ReenterPasswordTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func RegisterButtonTapped(_ sender: Any) {

let userEmail = userEmailTextField.text
let userPassword = userPasswordTextField.text
let userReenterPassword = ReenterPasswordTextField.text

// Check for empty fields
if((userEmail?.isEmpty)! || (userPassword?.isEmpty)! ||
(userReenterPassword?.isEmpty)!)
{
//Display alert message
displayAlertMessage(userMessage: "All fields are required")
return;
}

//Check if passwords match
if(userPassword != userReenterPassword)
{
// Display an alert message
displayAlertMessage(userMessage: "Passwords do not match")
return;
}

// Store data
UserDefaults.standard.set(userEmail, forKey:"userEmail")
UserDefaults.standard.set(userEmail, forKey:"userPassword")
UserDefaults.standard.synchronize()

// Display an alert message
displayAlertMessage(userMessage: "Registration is successful.Thank you!")
}

func displayAlertMessage(userMessage: String) {

let myAlert = UIAlertController(title:"Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.alert)

let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default) {
action in
self.dismiss(animated: true, completion:nil)
}

myAlert.addAction(okAction);

self.present(myAlert, animated: true, completion: nil)
}

}

关于ios - 使用未解析的标识符 'displayAlertMessage',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47361470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com