简体   繁体   English

无法将类型“布尔”的值分配给类型“ UIButton?”

[英]Cannot assign value of type 'Bool' to type 'UIButton?'

I am trying to hide a button, until another condition is met. 我试图隐藏一个按钮,直到满足其他条件。 When i load the app i am using the slider and when it reaches the max, it should make the button visible, but for some weird reason it won't. 当我加载应用程序时,我正在使用滑块,当滑块达到最大值时,它应该使按钮可见,但是出于某些奇怪的原因,它不会。 I have just done it in another app with no issues and the code is almost identical.? 我刚刚在另一个没有问题的应用程序中完成了该操作,并且代码几乎相同。

Can't figure out what to do tbh. 无法弄清楚该怎么办。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated) 
    profileVisible.isHidden = true
}

@IBAction func btnClicked(_ sender: Any) { 

    motionManager.startDeviceMotionUpdates(to: queue) { (motion, error) in DispatchQueue.main.async {
        self.slider.value = Float((motion?.attitude.roll ?? 0 ) * 1.4)

        print(self.slider.value)

        if self.slider.value == 1.0 {
            self.profileVisible = false
            self.motionManager.stopDeviceMotionUpdates()


            AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); // vibrates when payment has succeded
        }

        if self.slider.value == -1.0 {
           profileVisible = true
            self.motionManager.stopDeviceMotionUpdates()
            AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
        }
    }
 }

You miss setting here 你错过这里的设置

if self.slider.value == 1.0 {
    self.profileVisible = false

And here 和这里

if self.slider.value == -1.0 {
     profileVisible = true

Should be 应该

profileVisible.isHidden = true/false // set it's value according to your logic 

profileVisible is of type UIButton you need to set it's isHidden property not it directly profileVisibleUIButton类型,您需要将其设置为isHidden属性,而不是直接设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将 Bool 类型的值分配给类型字符串数据库表示 - Cannot assign value of Bool type to type String Database Representation 无法将类型'(String ?, Bool,[AnyObject] ?, NSError?)->()'的值分配给 - Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to 无法分配类型'(String!,Bool,[AnyObject]!,NSError!) - > Void的值为UIActivityViewControllerCompletionWithItemsHandler类型的值?' - Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?' 无法分配值类型 - Cannot not assign Value Type 无法将类型“()”的值转换为指定类型“Bool” - Cannot convert value of type '()' to specified type 'Bool' 无法使用类型为“UIButton”的索引下标类型为 [uiButton] 的值(Swift) - Cannot subscript a value of type [uiButton] with an index of type 'UIButton' (Swift) 无法分配通用类型的值 - Cannot assign value of generic type 无法将类型“任何”的值分配给类型“字符串?” - Cannot assign value of type 'Any' to type 'String?' AVPlayer无法将类型的值分配给type - AVPlayer cannot assign value of type to type 无法分配类型的值以键入UITableViewDataSource - Cannot assign a value of type to type UITableViewDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM