I'm new in this website, and I already know that it helps me a LOT in coding, so thanks to the founder of this website and to the questioners and the answerers and everyone else :D
Still, one problem I have though. I have this 'Missing Argument for Parameter #1 in call' error. Its really annoying me, I'm trying to make an app, and for how much time I put into this app, I don't want to delete it. Please.
So here is the code:
class ViewController: UIViewController {
#IBOutlet var UsernameTextField: UITextField!
#IBOutlet var PasswordTextField: UITextField!
#IBOutlet var EmailTextField: UITextField!
#IBAction func LogIn(sender: AnyObject) {
}
#IBAction func SignUp(sender: AnyObject) {
SignUp() //The error is here
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
func SignUp(){
var user = PFUser()
user.username = UsernameTextField.text
user.password = PasswordTextField.text
user.email = EmailTextField.text
}
let user = PFUser()
user.username = "Name:"
user.password = "Pass:"
user.email = "Email:"
user.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
if error == nil {
// Hooray! Let them use the app now.
} else {
// Examine the error object and inform the user.
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
You've got two functions with the same name, you should rename one of them!
First function:
#IBAction func SignUp(sender: AnyObject)
Second function:
func SignUp()
The reason you get the error is because the compiler is trying to use your first function rather than the second one, so the easiest way to fix it is to change the name of one of the functions.
Related
I am working in X-code 9 beta Swift 4, and can run and build but get the following error and only a white screen loads:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[myapp.logInVC _finishDecodingLayoutGuideConnections:]: unrecognized selector sent to instance 0x10251ead0'
Not sure what _finishDecodingLayoutGuideConnections is?
I checked all my selectors, but didn't see an issue. This is a login screen using Firebase, and my hope would be if login is successful it will load the View Controller.
Any help would be much appreciated!
class logInVC: UIViewController {
#IBOutlet weak var signInSelector: UISegmentedControl!
#IBOutlet weak var signInLabel: UILabel!
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var passwordTextField: UITextField!
var isSignIn:Bool = true
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 signInSelectorChanged(_ sender: UISegmentedControl) {
switch signInSelector.selectedSegmentIndex
{
case 0:
signInLabel.text = "sign in";
case 1:
signInLabel.text = "create account";
default:
break
}
}
#IBAction func signInButtonTapped(_ sender: UIButton) {
if isSignIn {
//validation
if let email = emailTextField.text, let pass = passwordTextField.text
{
//sign in with Firebase
Auth.auth().signIn(withEmail: email, password: pass) { (user, error) in
// make sure user isn't nil
if user != nil {
//user is found, go to AR experience
self.performSegue(withIdentifier: "goToHome" , sender: self)
}
else {
//error, check error and show message
}
}
}
else {
//register with Firebase
Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in
// make sure user isn't nil
if user != nil {
//user is found, go to AR experience
self.performSegue(withIdentifier: "goToHome" , sender: self)
}
else {
//error, check error, and show message
}
}
Check whether your IBOutlets and IBActions are properly connected. The error occurs when your XiB and Class files are not properly setup.
I can't seem to get this to work. The database portion works and I'm getting user info as intended in the database, but it is not creating users in Firebase Auth. For the following code, it printed "can't register."
Can someone please tell me what I'm doing wrong?
import UIKit
import Firebase
import FirebaseAuth
class AddUserTableViewController: UITableViewController, UITextFieldDelegate {
#IBOutlet weak var firstNameTextField: UITextField!
#IBOutlet weak var emailTextField: UITextField!
#IBAction func saveUserButton(_ sender: Any) {
let ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()
FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: "pass", completion: { (user, error) in
if error != nil {
print ("Can't Register")
}
else {
print ("I don't know what this means")
}
})
ref?.child("Users").childByAutoId().setValue(["First Name": self.firstNameTextField.text, "Email": self.emailTextField.text])
}
Just include Firebase, you don't need to include FirebaseAuth as well on each page.
Here's my working code for FireBase login, I did this from a Youtube tutorial a few weeks ago.
import UIKit
import Firebase
class LoginController: UIViewController {
#IBOutlet weak var menuButton:UIBarButtonItem!
#IBOutlet weak var signinSelector: UISegmentedControl!
#IBOutlet weak var signinLabel: UILabel!
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var passwordTextField: UITextField!
#IBOutlet weak var signinButton: UIButton!
var isSignIn:Bool = true
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func signinSelectorChanged(_ sender: UISegmentedControl) {
//Flip the boolean true to false
isSignIn = !isSignIn
//Check the boolean and set the buttons and labels
if isSignIn {
signinLabel.text = "Sign In"
signinButton.setTitle("Sign In", for: .normal)
}
else {
signinLabel.text = "Register"
signinButton.setTitle("Register", for: .normal)
}
}
#IBAction func signinButtonTapped(_ sender: UIButton) {
//Do some form validation on email and password
if let email = emailTextField.text, let pass = passwordTextField.text
{
//Check if it's signed or register
if isSignIn {
//Sign in the user with Firebase
Auth.auth().signIn(withEmail: email, password: pass, completion: { (user, error) in
//Check that user isn't nil
if let u = user {
//User is found, goto home screen
self.performSegue(withIdentifier: "goToHome", sender: self)
}
else{
//Error: Check error and show message
}
})
}
else {
//Register the user with Firebase
Auth.auth().createUser(withEmail: email, password: pass, completion: { (user, error) in
//Check that user isn't NIL
if let u = user {
//User is found, goto home screen
self.performSegue(withIdentifier: "goToHome", sender: self)
}
else {
//Check error and show message
}
})
}
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//Dismiss the keyboard when the view is tapped on
emailTextField.resignFirstResponder()
passwordTextField.resignFirstResponder()
}
}
Below is the code, hope anyone can help me solve the Use of unresolved identifier 'SignUp' problem:
#IBOutlet var UsernameTextField: UITextField!
#IBOutlet var PasswordTextField: UITextField!
#IBOutlet var EmailTextField: UITextField!
#IBAction func LogIn(sender: AnyObject) {
}
#IBAction func Signup(sender: AnyObject) {
SignUp() //Error is here.
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
func SignUp(){
var user = PFUser()
user.username = UsernameTextField.text
user.password = PasswordTextField.text
user.email = EmailTextField.text
}
let user = PFUser()
user.username = "Name:"
user.password = "Pass:"
user.email = "Email:"
user.signUpInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
if error == nil {
// Hooray! Let them use the app now.
} else {
// Examine the error object and inform the user.
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Make the function declaration and call start with a lower case s.
It's also worth noting you should name stuff so it's clear what is it.
#IBAction func signUpButton(sender: AnyObject) {
signUp() // Calling signUp function here that is declared below.
}
func signUp(){
// Do sign up stuff.
}
Dose anyone know how I can make a user sign up with parse in Swift Xcode 6.4?
I Have searched everything and can't find one that works.
I Tried this code but it did not work.
It said:
Use of unresolved identifier PFUser
import UIKit
class SignupViewController: UIViewController {
#IBOutlet var usernameTextField: UITextField!
#IBOutlet var passwordTextField: UITextField!
#IBOutlet var emailTextField: UITextField!
#IBOutlet var messageLabel: UILabel!
#IBAction func loginVerifyButton(sender: AnyObject) {
var usrEntered = usernameTextField.text
var pwdEntered = passwordTextField.text
var emlEntered = emailTextField.text
if usrEntered != "" && pwdEntered != "" && emlEntered != "" {
// If not empty then yay, do something
} else {
WrongInfo()
}
}
func userSignUp() {
var user = PFUser()
user.username = usrEntered
user.password = pwdEntered
user.email = emlEntered
}
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.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
func WrongInfo(){
var WrongInfo:UIAlertView = UIAlertView(title: "ALL FEILDS REQUIRED", message: "Please use all feilds!", delegate: self, cancelButtonTitle: "ok")
}
}
You need to import Parse , in Appdelegate.swift file! if still getting same error import Parse in signup view controller too
You have to create your own view and then implement it/segue users to it based on the users current status. If they click your sign up button segue them to a custom view and then act accordingly. You would sign them up with a function similar to what you have offered already in your question:
func myMethod() {
var user = PFUser()
user.username = "myUsername"
user.password = "myPassword"
user.email = "email#example.com"
// other fields can be set just like with PFObject
user["phone"] = "415-392-0202"
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
}
}
You essentially could use the same view you already have since your fields are identical but call different methods depending on the button they select.
I get the error in the title while trying to change the text of a label which is part of the Page class (a subclass of UIViewController)
#IBAction func StartButton(sender: AnyObject) {
for quote in quoteList {
var newPage = Page()
//error is on the next line:
newPage.Label.text = quote
pageArray!.append(newPage)
}
}
}
and here is the Page class:
class Page : UIViewController{
var index: Int = 0
var parent: PageArray?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var Label: UILabel!
#IBAction func previousButton(sender: AnyObject) {
}
#IBAction func gotoListButton(sender: AnyObject) {
}
#IBAction func nextButton(sender: AnyObject) {
}
}
I am new when it comes to swift programming, and iOs in general; I apologise if a similar question has already been asked. I searched first, but didn't find a solution that worked for me.
I suspect the problem is with the initialization of newPage, and tried doing it a few different ways, but I can't seem to get it right.
My question is what exactly am I doing wrong, and how can I fix it?
EDIT: Got it working like this (by working I mean not crashing and doing nothing):
#IBAction func StartButton(sender: AnyObject) {
var pageArray: PageArray = PageArray()
for quote in quoteList {
var newPage = Page(nibName: "Page", bundle: nil)
if newPage.Label != nil {
newPage.Label.text = quote
}
pageArray.append(newPage)
}
}
It seems certain now that newPage.Label is nil.
Well, pageArray is probably nil and with ! you are pretending that it is not.
Instantiating pageArray should solve your issue.
You can check the first answer here to learn more about question and exclamation marks in swift
EDIT:
Your problem might also come from your controller initialization, you might want to try:
let mystoryboard:UIStoryboard = UIStoryboard(name: "storyboardName", bundle: nil)
var newPage:Page = mystoryboard.instantiateViewControllerWithIdentifier("idYouAssigned") as! Page
I knew your problems. When you load a ViewController from Nib. Actually It's take a delay time until your ViewController has been loaded.
This code below help your ViewController load immediate.
#IBAction func StartButton(sender: AnyObject) {
var pageArray: PageArray = PageArray()
for quote in quoteList {
var newPage = Page(nibName: "Page", bundle: nil)
let _ = newPage.view // A trick. It's help your view load immediate
// Your Page has been loaded.
newPage.Label.text = quote
pageArray.append(newPage)
}