草庐IT

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

codeneng 2023-03-28 原文

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 在代码中(再次:从情节提要)实例化视图控制器,但上述方法代码较少,做同样的事情,因此是首选。

  • 非常感谢你帮助我!
  • 嗯... Mundi,当我实例化视图控制器时,它只是给了我 TableViewController 的一部分。它没有给我 UI 元素,如按钮、文本字段等

有关关于 ios:不能将值类型”TableViewController.Type”转换为预期的参数类型”UIViewController”的更多相关文章

  1. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  2. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  3. ruby - RSpec - 使用测试替身作为 block 参数 - 2

    我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere

  4. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

    我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

  5. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  6. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

  7. ruby-on-rails - 在默认方法参数中使用 .reverse_merge 或 .merge - 2

    两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option

  8. ruby - 定义方法参数的条件 - 2

    我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano

  9. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  10. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

随机推荐