I reformatted to get it more readable.
(IBAction)connectButtonTouched:(id)sender {
BOOL typeOFAction; // Determine which Boat Connect Button was touched.
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.boatsAndDevicesTable];
NSIndexPath *indexPath = [self.boatsAndDevicesTable indexPathForRowAtPoint:buttonPosition]
NSLog(@"sender - %@", sender);
NSLog(@"sender - %@", ((UIButton *)sender).layer);
NSLog(@"button position - %f - %f", buttonPosition.x, buttonPosition.y);
NSLog(@"Index Path Section - %ld", (long)indexPath.section);
BoatWithStatus *boatForConnectButton = [self.boatsWithStatus objectAtIndex:indexPath.section-1];
I tested similar code in Swift (but with a single section)
@IBAction func testInCell(_ sender: UIButton) {
let buttonPosition = sender.convert(CGPoint.zero, to: self.tableForItem2)
let indexPath = self.tableForItem2.indexPathForRow(at: buttonPosition)
print(buttonPosition, indexPath)
}
Tested on simulators iOS 15.2 and 15.4 (Xcode 13.2.1 and Xcode 13.3).
It works correctly.
In your case, is section wrong or both section and row ?
Could you give an example (NSLogs) of wrong results (and print as well row).