Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在斯威夫特的一个案例中,有可能做出一个顺序吗?_Ios_Swift_Enums - Fatal编程技术网

Ios 在斯威夫特的一个案例中,有可能做出一个顺序吗?

Ios 在斯威夫特的一个案例中,有可能做出一个顺序吗?,ios,swift,enums,Ios,Swift,Enums,我以编程方式制作了一个设置菜单,它使用枚举和事例作为单元格信息 enum SettingsSection: Int, CaseIterable, CustomStringConvertible { case Social case Communications var description: String { switch self { case .Social: return "General" case .Comm

我以编程方式制作了一个设置菜单,它使用枚举和事例作为单元格信息

enum SettingsSection: Int, CaseIterable, CustomStringConvertible {
    case Social 
    case Communications

    var description: String {
        switch self {
        case .Social: return "General"
        case .Communications: return "Communication"
        }
    }
}
当我试图让一个细胞执行一个序列时,问题就出现了。 此Swift文件中没有“self”。因此,我在视图控制器中创建了一个函数,并尝试使用该函数执行以下步骤:

    var description: String {
        switch self {
        case .editProfile: return "Edit Profile"
        case .logout:
            SettingsViewController().Logout()
            return "Log Out"
        }
    }
在我运行应用程序并单击单元格之前,它不会给出错误,出现的错误是:

 Get It Done[8620:987786] Warning: Attempt to present <Get_It_Done.ViewController: 
0x1017af660> on <Get_It_Done.SettingsViewController: 0x1017aed20> whose view is not in the window hierarchy!
Optional("Log Out")

实际上很难说,部分原因是你(对我)的问题有些模糊。但是我会在两个单独的评论中给你两个帮助。首先,关于赛格。。。。它们实际上属于IB。您无法在代码中创建和执行它们。但好消息是,segue只需在导航控制器堆栈中推/弹出视图控制器。这在代码中很容易做到。第二,关于你的错误。它表明视图层次结构有问题。也就是说,名为
SettingsViewController
的东西应该已经在层次结构中,但没有。这就是你的问题让它变得困难的地方——到目前为止,你无法复制的东西。根据你所说的——基本上你是在尝试从你“以编程方式”创建的设置菜单中“执行一个序列”——我建议你设置一个新项目,并尝试做你想做的事情(是从一个VC移动或推/弹出到另一个VC?还是从另一个VC呈现一个VC?),但不要设置菜单。
 public func Logout() {
    let vc = ViewController() //your view controller
    self.present(vc, animated: true, completion: nil)
}