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

tableview cell 點選無反應 #2

Open
joseph-517 opened this issue Oct 30, 2019 · 3 comments
Open

tableview cell 點選無反應 #2

joseph-517 opened this issue Oct 30, 2019 · 3 comments

Comments

@joseph-517
Copy link

joseph-517 commented Oct 30, 2019

謝謝你的分享

請問點選cell的問題
sample中的cellPressed在prepareForReuse中設定 viewModel?.cellPressed = nil,
滑動tableview時觸發 prepareForReuse後,點選cell就呼叫不到,
viewModel?.cellPressed = nil 拿掉這行即正常。但是否會造成 retain cycle?
請問是什麼問題呢?謝謝

@rocooshiang
Copy link

rocooshiang commented Oct 31, 2019

viewModel?.cellPressed = nil 拿掉這行即正常。但是否會造成 retain cycle?


我也剛好遇到這個問題,後來的解法是將 viewModel.cellPressed = { ... } 移到 Cell 的 setup function,prepareForReuse保持viewModel?.cellPressed = nil

@joseph-517
Copy link
Author

我也剛好遇到這個問題,後來的解法是將 viewModel.cellPressed = { ... } 移到 Cell 的 setup function,prepareForReuse保持viewModel?.cellPressed = nil

@rocooshiang 謝謝你的分享
移到cell裡的setup function後可以點選,但要如何傳給原先vc的vm做對應的處理呢?
範例中的 addBtnPressed 似乎也是同樣的情況

@koromiko
Copy link
Owner

koromiko commented Nov 1, 2019

Hello
的確那個viewModel?.cellPressed = nil是需要拿掉的
抱歉這個應該是程式的bug
如果設定cell的view model時沒有參照到sel或者有記得用weak self,就不用擔心Retain cycle的問題囉

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

3 participants