ios - 无法将类型 'listOfContacts' 的值转换为预期参数类型 'UIViewController'

标签 ios swift

这是代码

let logButton : UIButton = {
    let login = UIButton()


    login.translatesAutoresizingMaskIntoConstraints = false

    login.setTitle("Login", for: .normal)
    login.setTitleColor(UIColor.white, for: .normal)
    login.backgroundColor = UIColor(red: 0/255, green: 61/255, blue: 114/255, alpha: 1.0)

    login.addTarget(self, action: #selector(loginButton), for: .touchUpInside)

    return login
}()


@objc func loginButton(){
    let contactList = listOfContacts()
    present(contactList, animated: true, completion: nil)

}

Cannot convert value of type 'listOfContacts' to expected argument type 'UIViewController'

请为此提供建议或解决方案

最佳答案

你的问题就在这里

 let contactList = listOfContacts()
 present(contactList, animated: true, completion: nil)

您尝试使用 listOfContacts 类型的 contactList 作为 present 方法的参数,该方法采用 UIViewController 类型作为第一个参数这是应该呈现的 VC

这是方法签名

func present(_ viewControllerToPresent: UIViewController,animated flag: Bool,completion: (() -> Void)? = nil)

关于ios - 无法将类型 'listOfContacts' 的值转换为预期参数类型 'UIViewController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48719419/

相关文章:

ios - didUpdateUserLocation 当 userLocation 的 View 是自定义时不调用

swift - 设备方向更改时如何更改 UiCollectionView 单元格大小?

ios - 我们可以打开 watch 扩展上的联系人吗

ios - 如何创建 NSMutableArray 并为其分配特定对象?

c# - 应用程序启动错误 : Foundation. MonoTouchException:抛出 Objective-C 异常 (Xamarin iOS)

ios - 获取用于在 Swift 中恢复应用内购买的已购买产品 ID 列表

ios - 在 WebView 中仅显示来自 HTML 的表格/标签

ios - View 中CircleView的Circle位置错误

swift - 错误 'cannot convert value of type ' int' 到预期参数类型 'UInt'

ios - 在不同的项目/包中使用对 Storyboard的 Storyboard引用似乎已损坏