调用 performSegue 函数时出错
Error while invoking performSegue function
我可以在 alamofire 验证处理程序之外调用我的 performSegue
。但我想在 alamofire 请求成功后继续
这是我的代码
Alamofire.request("link", method: .post, parameters: parameters!, encoding: JSONEncoding.default).responseJSON { response in
switch response.result {
case .success:
performSegue(withIdentifier: "successRegistration", sender: Any?)
case .failure(let error):
print(error)
}
}
问题出在下一行
performSegue(withIdentifier: "successRegistration", sender: Any?)
它向我显示以下错误
expected member name or constructor call after type name
和 xcode 给了我两个修复,一个是将 Any?
更改为 Any?()
这给了我另一个错误,如下所示:
cannot invoke initializer for type 'Any?' with no arguments
另一个修复方法是将 Any?
更改为 Any?.self
,这给了我另一个错误显示如下:
Implicit use of 'self' in closure, use 'self.' to make capture semantics explicit
当我将 Any?
更改为 nil
时,出现同样的问题(如上)
导致此错误的原因是什么? (知道当我将 Any?
更改为 nil
时,performSegue
函数在 Alamofire 之外工作正常)
试试这个:
self.performSegue(withIdentifier: "successRegistration", sender: nil)
一些注意事项:
在一个闭包中,你总是需要使用 self
来引用外部对象。在您的情况下,那将是 UIViewControlller
。
Any
是类型名称(协议)而不是值。要指定 "empty" 值,请改用 nil
。使用 Any
作为一般值的 类型 ,没有 defined/known 类型。
self.performSegueWithIdentifier("successRegistration", sender: nil)
尝试在 performSegue 函数之前使用 "self"。
为什么要传递 "Any?" 作为参数。它类似于 Int 或 Bool 等数据类型。如果你不想传递任何东西,只需发送 nil。
我可以在 alamofire 验证处理程序之外调用我的 performSegue
。但我想在 alamofire 请求成功后继续
这是我的代码
Alamofire.request("link", method: .post, parameters: parameters!, encoding: JSONEncoding.default).responseJSON { response in
switch response.result {
case .success:
performSegue(withIdentifier: "successRegistration", sender: Any?)
case .failure(let error):
print(error)
}
}
问题出在下一行
performSegue(withIdentifier: "successRegistration", sender: Any?)
它向我显示以下错误
expected member name or constructor call after type name
和 xcode 给了我两个修复,一个是将 Any?
更改为 Any?()
这给了我另一个错误,如下所示:
cannot invoke initializer for type 'Any?' with no arguments
另一个修复方法是将 Any?
更改为 Any?.self
,这给了我另一个错误显示如下:
Implicit use of 'self' in closure, use 'self.' to make capture semantics explicit
当我将 Any?
更改为 nil
导致此错误的原因是什么? (知道当我将 Any?
更改为 nil
时,performSegue
函数在 Alamofire 之外工作正常)
试试这个:
self.performSegue(withIdentifier: "successRegistration", sender: nil)
一些注意事项:
在一个闭包中,你总是需要使用
self
来引用外部对象。在您的情况下,那将是UIViewControlller
。Any
是类型名称(协议)而不是值。要指定 "empty" 值,请改用nil
。使用Any
作为一般值的 类型 ,没有 defined/known 类型。
self.performSegueWithIdentifier("successRegistration", sender: nil)
尝试在 performSegue 函数之前使用 "self"。
为什么要传递 "Any?" 作为参数。它类似于 Int 或 Bool 等数据类型。如果你不想传递任何东西,只需发送 nil。