Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot covert value type 'TableViewController.Type' to expected argument type 'UIViewController'

I am making an app with a sign up and login. I used Parse for this. I want to move the View Controller to a TableViewController if the Login/Sign Up is successful. However I am getting this error: "Cannot convert value type'TableViewController.Type' to expected argument type 'UIViewController'.

Here is the line I am getting the error in:

func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) {
    self.dismissViewControllerAnimated(true, completion: nil)
    self.presentViewController(TimelineTableViewController, animated: true, completion: nil)


}

And here is the whole code:

//  Created by Ojas Sethi on 12/10/15.
//  Copyright © 2015 Jell Apps. All rights reserved.
//

import UIKit
import Parse
import ParseUI

class LoginSignupViewController: UIViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate {
    var logInViewController: PFLogInViewController = PFLogInViewController()
    var signUpViewController: PFSignUpViewController = PFSignUpViewController()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        if (PFUser.currentUser() == nil){
            self.logInViewController.fields = PFLogInFields.UsernameAndPassword
            self.logInViewController.fields = PFLogInFields.LogInButton
            self.logInViewController.fields = PFLogInFields.SignUpButton
            self.logInViewController.fields = PFLogInFields.PasswordForgotten
            self.logInViewController.fields = PFLogInFields.DismissButton

            /*| PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.PasswordForgotten | PFLogInFields.DismissButton*/

            let logoInLogoTitle = UILabel()
            logoInLogoTitle.text = "Ziffer"
            logoInLogoTitle.font = UIFont.systemFontOfSize(25)

self.logInViewController.logInView?.logo = logoInLogoTitle
            self.logInViewController.delegate = self

            let signUpLogoTitle = UILabel()
            signUpLogoTitle.text = "Ziffer"
            logoInLogoTitle.font = UIFont.systemFontOfSize(25)

            self.signUpViewController.signUpView?.logo = signUpLogoTitle
            self.signUpViewController.delegate = self
            self.logInViewController.signUpController = self.signUpViewController
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func logInViewController(logInController: PFLogInViewController, shouldBeginLogInWithUsername username: String, password: String) -> Bool {
        if (!username.isEmpty || !password.isEmpty){
            return true
        }else{
            return false
        }
    }

    func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) {
        self.dismissViewControllerAnimated(true, completion: nil)
        self.presentViewController(TimelineTableViewController, animated: true, completion: nil)
    }

    func logInViewController(logInController: PFLogInViewController, didFailToLogInWithError error: NSError?) {
        print("failed to login")
    }

    func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) {
        self.dismissViewControllerAnimated(true, completion: nil)
        self.presentViewController(logInViewController, animated: true, completion: nil)
        SignUpSuccessfulAlert()

    }

    func signUpViewController(signUpController: PFSignUpViewController, didFailToSignUpWithError error: NSError?) {
        print("Failed to signup...")

        SignUpFaliedAlert()
    }

    func signUpViewControllerDidCancelSignUp(signUpController: PFSignUpViewController) {
        print("User dismissed sign up.")
    }

    func SignUpSuccessfulAlert(){
        var alertController : UIAlertController
    alertController = UIAlertController(title: "Sign Up Successful", message: "Yay! Sign up was successful! Now you can start using Ziffer!", preferredStyle: .Alert)

        let doneAction = UIAlertAction(title: "Ok", style: .Default, handler: nil)

        alertController.addAction(doneAction)

        self.presentViewController(alertController, animated: true, completion: nil)
    }

    func SignUpFaliedAlert(){
        var signUpalertFail : UIAlertController

        signUpalertFail = UIAlertController(title: "Failed", message: "Sorry! Sign up faield. Check the connections and try again later", preferredStyle: .Alert)

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

        signUpalertFail.addAction(okAction)

        self.presentViewController(signUpalertFail, animated: true, completion: nil)
    }
}
like image 361
ojassethi Avatar asked Mar 14 '23 10:03

ojassethi


2 Answers

First, you are trying to present your new view controller from login view controller which is about to dismiss. Thats not right. You would want to present it from stable view controller who presented login view controller. Here is nice example on how to do this. This is based on objective-c so bear with it.

Second, you would need to create an object of TimelineTableViewController to present in view hierarchy (again take a look at the link I shared above). Something like this:

let timeLineTableVC = TimelineTableViewController()
self.presentViewController(timeLineTableVC, animated: true, completion: nil)
like image 167
Abhinav Avatar answered Apr 27 '23 19:04

Abhinav


Your (capitalized) TimelineTableViewController seems to be a class, not a class instance. You need to first create an instance of this controller.

The recommended way to do this is to create a segue to this controller in storyboard and then call performSegueWithIdentifier when you want to present the controller.

The closest thing to your code would be to instantiate the view controller in code (again: from the storyboard) with instantiateViewControllerWithIdentifier, but the above method is less code, does the same thing and is thus preferred.

like image 37
Mundi Avatar answered Apr 27 '23 20:04

Mundi