Access a MobileScreen method from a Custom Table Cell?

I’ve got a custom table cell with up and down buttons to increment and decrement a global variable. That works great. But when I do this I need to refresh the MobileScreen labels and reload the table row.

In the past I’ve used a weakref to save the current screen when using a container control in a scrollable area, but I’m confused where to do the equivalent thing with a custom table cell.

Help me Obiwan!

You could use the notifier pattern for this using the Notification_Center module in iOSKit. It’s the only pure Xojo module in it. Basically when the value changes you issue a notification from the cell, and you have the view subscribe to the notification and update accordingly

1 Like

Another way is to create a delegate in your custom table cell, with a local property of that type, and set it to the AddressOf a callback method on your MobileScreen when you instantiate the custom table cell. Then whenever you need to callback into the MobileScreen to update some value, you can invoke that from within the custom table cell.

1 Like

I have figured out how to get a reference to the calling screen in a local variable in the custom table cell.

parentView As MobileScreen

But I can’t figure out how to access:
callingscreen.table1.ReloadDataSource
callingscreen.UpdateDisplay 'method

I’m clueless on Delegates.

I can ReloadDataSource by accessing Controls, but how do you get to a method on the screen?

OK, here’s what I did based on mining the forum for old threads with examples. Since my MobileScreen has a Table which uses a DataSource which uses a Custom Cell I opted to create a Delegate (UpdateLimbsScreen) and a Global Property(UpdateCallBack) of type UpdateLimbsScreen in a Shared Module. Color me rookie.

In the Opening event of the Screen:

UpdateCallBack = WeakAddressOf UpdateDisplay 'the method I want to call

In the Custom Table Cell I created a method:

Private Sub UpdateScreen(callback As UpdateLimbsScreen)
If callback <> Nil Then
callback.Invoke
End If
End Sub

In the Custom Cell I have Up and Down buttons. In the Pressed event handlers for these buttons:

Self.UpdateScreen(UpdateCallBack)

Hope this is helpful for others that struggle with these concepts.