首页 > 解决方案 > CoocaPod:“.....”类型的值没有成员“....”,但应该有

问题描述

我正在使用这个 cocoapod来创建一个小弹出视图来重置所有存储的 UserDefaults。因此,我希望弹出窗口的“是”和“否”按钮水平对齐(默认为垂直)。这是我的代码:

resetBtn.touchUpInside{ [self] in
        let dialogAppearance = PopupDialogDefaultView.appearance()
        let buttonAppearance = DefaultButton.appearance()
        let title = "Do you really want to reset this game?"
        let popup = PopupDialog(title: title)
        let yesBtn = DefaultButton(title: "Yes", height: 60) {
            self.click()
            defaults.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
            defaults.synchronize()
        }
        let noBtn = DefaultButton(title: "No", height: 60) {
            self.click()
        }
        popup.addButton(yesBtn)
        popup.addButton(noBtn)
        dialogAppearance.messageFont = UIFont(name: "Nunito-Black", size: 18)!
        dialogAppearance.messageTextAlignment = .natural
        dialogAppearance.titleFont = UIFont(name: "Nunito-Black", size: 22)!
        buttonAppearance.titleFont = UIFont(name: "Nunito-Black", size: 22)!
        let vc = popup.viewController as! PopupDialogDefaultViewController //!!! 
        vc.buttonAlignment = .horizontal /// Cannot infer contextual base in reference to member 'horizontal', Value of type 'PopupDialogDefaultViewController' has no member 'buttonAlignment'
        self.present(popup, animated: true, completion: nil)
    }

正如您在此处看到的,Creator 将按钮水平放置:

    let vc = popup.viewController as! PopupDialogDefaultViewController
    vc.buttonAlignment = .horizontal

但是当我这样做时,编译器会说“无法根据成员'horizo​​ntal'推断上下文基础”,“'PopupDialogDefaultViewController'类型的值没有成员'buttonAlignment' ”......正如我的代码中所标记的那样。

我应该怎么办?

标签: iosswiftxcodecocoapods

解决方案


解决了:

直接写就行了
let popup = PopupDialog(title: title, message: message, buttonAlignment: .horizontal)


推荐阅读