-1

I keep getting this error. I know why I am getting it but having trouble finding it. Is there a trick in Xcode to finding the exact variable that is causing this?

Error Image

In the image above it shows the error on the line that passes the data from the cell to the button. Would this error be located in the actual cell or in the button section?

BTR199234
  • 3
  • 2

1 Answers1

0
let tag = sender.tag

This line of code is dangerous because by the time your code is running. The tag that specify the row of the cell maybe just invisible or even worse your datasource is already changed so that you won't get the cell and instead you get the nil.

I'll just quote from the document of the method cellForRow(at:).

Return Value
An object representing a cell of the table, or nil if the cell is not visible or indexPath is out of range.

Check https://developer.apple.com/documentation/uikit/uitableview/1614983-cellforrow for more details.

zhoujialei
  • 435
  • 5
  • 12
  • Thanks. That has to be the issue. Been searching the past 4 hours for alternative ways to do this. Do you know of any? I tried superview and that didn't work. – BTR199234 Aug 18 '20 at 10:29
  • I can't tell only by the code snippet you provided @BTR199234 – zhoujialei Aug 18 '20 at 11:00