TheGreatWall icon indicating copy to clipboard operation
TheGreatWall copied to clipboard

tableview cell 點選無反應

Open joseph-517 opened this issue 5 years ago • 3 comments

謝謝你的分享

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

joseph-517 avatar Oct 30 '19 15:10 joseph-517

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


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

rocooshiang avatar Oct 31 '19 06:10 rocooshiang

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

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

joseph-517 avatar Nov 01 '19 15:11 joseph-517

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

koromiko avatar Nov 01 '19 16:11 koromiko