关于 ios:不能将值类型”TableViewController.Type”转换为预期的参数类型”UIViewController”

cannot covert value type ‘TableViewController.Type’ to expected argument type ‘UIViewController’

我正在制作一个注册和登录的应用程序。我为此使用了 Parse。如果登录/注册成功,我想将视图控制器移动到 TableViewController。但是我收到此错误:”无法将值类型//’TableViewController.Type//’ 转换为预期的参数类型//’UIViewController//’。

这是我收到错误的行:

1
2
3
4
5
6
func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) {
    self.dismissViewControllerAnimated(true, completion: nil)
    self.presentViewController(TimelineTableViewController, animated: true, completion: nil)

}

这是完整的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//  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)
    }
}


首先,您尝试从即将关闭的登录视图控制器中展示您的新视图控制器。那是不对的。您可能希望从提供登录视图控制器的稳定视图控制器中呈现它。这是关于如何做到这一点的好例子。这是基于objective-c的,所以请耐心等待。

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

1
2
let timeLineTableVC = TimelineTableViewController()
self.presentViewController(timeLineTableVC, animated: true, completion: nil)

您的(大写) TimelineTableViewController 似乎是一个类,而不是一个类实例。您需要首先创建此控制器的实例。

推荐的方法是在情节提要中为此控制器创建一个segue,然后在您想要呈现控制器时调用performSegueWithIdentifier

最接近您的代码的方法是使用 instantiateViewControllerWithIdentifier 在代码中(再次:从情节提要)实例化视图控制器,但上述方法代码较少,做同样的事情,因此是首选。


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268645.html

(0)
上一篇 2022年6月20日
下一篇 2022年6月20日

相关推荐

发表回复

登录后才能评论