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 - StoryBoard - UITabBarController + UINavigationController - 从一个导航 Controller 跳转到另一个

ios - main 方法和 block 中的内存泄漏

切换到另一个 VC Swift 后,iOS 动画无法正常工作

ios - SKEmiterNode 与 AVAudioPlayer 用于音乐视觉效果

ios - Swift 获取总行驶距离 ios 9

iphone - 无法通过 YAJLiOS 解析 json 数据

iphone - 适用于 iOS 应用程序的分析库

objective-c - 为什么分配时需要临时变量?

ios - UIViewController 在被告知不要这样做时更改方向

ios - 从 NSLocale.preferredLanguages 数组中删除区域代码