iOS 13 SelectSectionAndRow crash

I’m using the SelectSectionAndRow method from the examples folder to select a row from an iOSTable. Using Xojo 2018r3. In iOS 13 this method crashes the app. I narrowed it down to the function: initPath(rowPath, section). I’m not sure why it’s crashing at this point - anyone experiencing the same thing/have any ideas? Thanks.

I have seen some inconsistencies in the code from SelectSectionAndRow

Please test this code instead:

[code]// If the section/row is invalid then raise an
// OutOfBoundsException
If section > table.SectionCount - 1 Or _
section < 0 Or _
row > table.RowCount(section) - 1 Or _
row < 0 Then
Raise New OutOfBoundsException
Return
End If

// Select the specified section/row

// https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/index.html#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:
// https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/index.html#//apple_ref/occ/instm/NSIndexPath/initWithIndex:
// scrollToRowAtIndexPath:atScrollPosition:animated:

Declare Function NSClassFromString Lib “Foundation” (classname As CFStringRef) As Ptr
Declare Function alloc Lib “Foundation” selector “alloc” (classRef As Ptr) As Ptr

// Create an instance of NSIndexPath with the section/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 function initPath Lib “Foundation” Selector “initWithIndex:” (id As Ptr, row As UInteger) as ptr
dim sectionPath As ptr = initPath(rowPath, section) // This is the section containing the row

// 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(sectionPath, row) // This is the row to select

// 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(table.Handle, fullPath, True, 0)

// 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(table.Handle, fullPath, 0, True)
[/code]

1 Like

That worked, thanks Jeremie!