Using drawCell override with object subclasses?

I'm curious if anybody has advice on how to best work with the gridview override functions inside of an object subclass? It's a few times now where I've wanted to do something like:

function self.listView:drawCell(section, row, column, selected, x, y, width, height)
	gfx.drawTextInRect(self.optionsList[row], x, y, width, height)
end

But instead need to redeclare that value first to access it properly:

local text = self.optionsList
function self.listView:drawCell(section, row, column, selected, x, y, width, height)
	gfx.drawTextInRect(text[row], x, y, width, height)
end

Maybe I'm missing a key concept of the SDK's implementation of subclasses here, though. Let me know if anyone else has come across this. Thanks!

1 Like

A couple idea pop to mind, nothing 'good' though :playdate_agh:

  • could you subclass gridview? might require a bigger refactor but might work.
  • you could back reference, ie: self.listview.parent = self and then use that in the override function

other that that I'm not sure :playdate_question:

1 Like

Yes, this was the first thing I thought of as well! I wanted to avoid it...

I'll try the back reference and report back, thanks Rob !