Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLRecordVernierCaliperCell 滑動時候卡尺標籤數字沒有切換 #12

Open
zhunghan opened this issue Jun 16, 2023 · 0 comments
Open

Comments

@zhunghan
Copy link

zhunghan commented Jun 16, 2023

版主你好,游標卡尺滑動時候數字沒有跟著更換。
我將 indexValueCallback 改寫到 setItem裡面處理。
其原因是因為self.item在還沒初始化之前他取不到值。所以原先block在guard語句之後就會返回。
後續的函數功能都不會執行。

我的理解是 -> indexValueCallback 不能寫在懶加載定義裡面。因為初始化的時候 自己的CellProtocol 協議還沒有值 self.item 會造成崩潰

所以進行了下面的修改
func setItem(_ item: CLRecordVernierCaliperItem, indexPath: IndexPath) {
self.vernierCaliperView.indexValueCallback = {[weak self] (value) in

        guard let weakSelf = self else { return }       //item -> CLRecordVernierCaliperItem
        weakSelf.item?.value = value.cgFloat
        weakSelf.item?.valueChangeCallback?(value)
        weakSelf.valueLabel.attributedText = weakSelf.attributedString(value, type: item.type)
    }

//其餘代碼
}

您參考看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant