Have this function that gets previously selected row in a table that was pushed off for new screen. Pressing back this is supposed to hilight the same row the user was on.
This is more than a few years old and this function now crashes the app.
Function RecallSelectedRow(iTable as iOSTable, lnRow As Integer, lnSection as Integer = 0)
'if lnRow = 0 then lnRow = -1
Declare Function NSClassFromString Lib "Foundation" (classname As CFStringRef) As Ptr
// And this one to create an instance
Declare Function alloc Lib "Foundation" selector "alloc" (classRef As Ptr) As Ptr
// Create an instance of NSIndexPath with the row to select
// Get pointer to class
Dim NSIndexPath As Ptr = NSClassFromString("NSIndexPath")
// Create an instance
Dim rowPath As Ptr = alloc(NSIndexPath)
// Now initialize it with initWithIndex:(NSUInteger)index
// Note the trailing ":" is very important!
Declare Sub initPath Lib "Foundation" Selector "initWithIndex:" (id As Ptr, row As UInteger)
initPath(rowPath, lnSection)
// Append the row and get back a new IndexPath with both
// (NSIndexPath *)indexPathByAddingIndex:(NSUInteger)index
Declare Function addIndex Lib "Foundation" Selector "indexPathByAddingIndex:" (id As Ptr, row As UInteger) As Ptr
Dim fullPath As Ptr
fullPath = addIndex(rowPath, lnRow) '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Crashes here.
// This is the correct initializer to use since we need two indexes
// Declare Sub initPath Lib "Foundation" Selector "initWithIndexes:length:" (id As Ptr, rows As Ptr, length As UInteger)
// Dim rows() As UInteger = Array(CType(0, UInteger), CType(2, UInteger)) // section, row
// initPath(rowPath, rows, rows.Ubound)
// Now that we have the index path, we can send it to the selectRow method from above
Declare Sub selectRow Lib "UIKit" Selector "selectRowAtIndexPath:animated:scrollPosition:" (id As Ptr, row As Ptr, animated As Boolean, scrollPosition As Integer)
// selectRow(Table1.Handle, rowPath, True, 0)
selectRow(iTable.Handle, fullPath, True, 0)
// This crashes. Check the console log and look at the report.
// Report says:
// *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
// reason: 'Invalid index path for use with UITableView.
// Index paths passed to table view must contain exactly two indices specifying the section and row.
// Please use the category on NSIndexPath in UITableView.h if possible.'
// Fix index path to add the section (0)
// We'll just append it
// (NSIndexPath *)indexPathByAddingIndex:(NSUInteger)index
// Now scroll to the row in case it is off the screen
// (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
// atScrollPosition:(UITableViewScrollPosition)scrollPosition
// animated:(BOOL)animated
Declare Sub scrollToRow Lib "UIKit" Selector "scrollToRowAtIndexPath:atScrollPosition:animated:" (id As Ptr, row As Ptr, scrollPosition As UInteger, animated As Boolean)
scrollToRow(iTable.Handle, fullPath, 0, True)