![](/img/trans.png)
[英]Cannot assign value of Bool type to type String Database Representation
[英]Cannot assign value of type 'Bool' to type 'UIButton?'
我試圖隱藏一個按鈕,直到滿足其他條件。 當我加載應用程序時,我正在使用滑塊,當滑塊達到最大值時,它應該使按鈕可見,但是出於某些奇怪的原因,它不會。 我剛剛在另一個沒有問題的應用程序中完成了該操作,並且代碼幾乎相同。
無法弄清楚該怎么辦。
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);
}
}
}
你錯過這里的設置
if self.slider.value == 1.0 {
self.profileVisible = false
和這里
if self.slider.value == -1.0 {
profileVisible = true
應該
profileVisible.isHidden = true/false // set it's value according to your logic
profileVisible
是UIButton
類型,您需要將其設置為isHidden
屬性,而不是直接設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.