HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 无法将值类型’TableViewController.Type’转换为预期的参数类型’UIViewController’大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在制作一个注册登录的应用程序.我为此使用了Parse.如果登录/注册成功,我想将View Controller移动到TableViewController.但是我收到此错误:“无法将值类型’TableViewController.Type’转换为期望的参数类型’UIViewController’.

这是我收到错误的行:

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


}

这是整个代码

//  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 @L_696_8@In@L_696_8@title = UILabel()
            @L_696_8@In@L_696_8@title.text = "Ziffer"
            @L_696_8@In@L_696_8@title.font = UIFont.systemFontOfSize(25)

self.logInViewController.logInView?.@L_696_8@ = @L_696_8@In@L_696_8@title
            self.logInViewController.delegate = self

            let signUp@L_696_8@title = UILabel()
            signUp@L_696_8@title.text = "Ziffer"
            @L_696_8@In@L_696_8@title.font = UIFont.systemFontOfSize(25)

            self.signUpViewController.signUpView?.@L_696_8@ = signUp@L_696_8@title
            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,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,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,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",handler: nil)

        signUpalertFail.addAction(okAction)

        self.presentViewController(signUpalertFail,completion: nil)
    }
}

解决方法

首先,您尝试从登录视图控制器呈现您的新视图控制器即将解散.那是不对的.您可能希望从呈现登录视图控制器的稳定视图控制器呈现它.这是关于如何做到这一点的 nice example.这是基于objective-c所以请耐心等待.

其次,您需要创建一个TimelineTableViewController对象以显示在视图层次结构中(再次查看我上面分享链接).像这样的东西:

let timeLineTableVC = TimelineTableViewController()
self.presentViewController(timeLineTableVC,completion: nil)

大佬总结

以上是大佬教程为你收集整理的ios – 无法将值类型’TableViewController.Type’转换为预期的参数类型’UIViewController’全部内容,希望文章能够帮你解决ios – 无法将值类型’TableViewController.Type’转换为预期的参数类型’UIViewController’所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。