Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegmentedRow crash due to selectedSegmentIndex == -1 #2238

Open
mikeymike9000 opened this issue Dec 13, 2022 · 9 comments
Open

SegmentedRow crash due to selectedSegmentIndex == -1 #2238

mikeymike9000 opened this issue Dec 13, 2022 · 9 comments

Comments

@mikeymike9000
Copy link

When selecting different Section Segments sometimes my app crashes due to segmentedControl.selectedSegmentIndex (within class SegmentedCell) returning a "-1" instead of legitimate value that is >=0

Existing Eureka code:
@objc (segmentedValueDidChange) func valueChanged() {
row.value = (row as! OptionsRow).options?[segmentedControl.selectedSegmentIndex]
}

Hack I'm using to avoid the crash:
@objc (segmentedValueDidChange) func valueChanged() {
if segmentedControl.selectedSegmentIndex == -1 { segmentedControl.selectedSegmentIndex = 0 }
row.value = (row as! OptionsRow).options?[segmentedControl.selectedSegmentIndex]
}

@mats-claassen
Copy link
Member

Have you been able to reproduce this issue? How does it happen that the selectedSegmentedIndex is -1? Does that happen when no segment is selected?

@mikeymike9000
Copy link
Author

Sorry I don't have more details yet and haven't figured out how to reproduce. It happens quite often so I'll create a video and screenshots next time I run into it. It occurs seemingly randomly when changing from one segment to another after setting them up like this:

<<< SegmentedRow("segs") { $0.value = "Tab1"; $0.options = ["Tab1", "Tab2", "Tab3"] }
<<< SegmentedRow ("segsTab1") { $0.value ="SubTab1"; $0.options = ["SubTab1", "SubTab2", "SubTab3"]; $0.hidden = "$segs != 'Tab1'" }

It occurs on devices as well as simulators and "My Mac (Designed for iPad)", and has been occurring through MacOS 12/13 and Xcode 13/14.

@mikeymike9000
Copy link
Author

ok I figured out how to recreate:

  1. run my iOS app as "My Mac (Designed for iPad)"
  2. click on the window of another open app to make that app active
  3. click back in the window of my app directly on a Eureka segment

I can only recreate this when running as "My Mac (Designed for iPad)" app and only when the app Touch Alternatives is turned off.

Screenshot 2022-12-13 at 3 42 03 PM

@mikeymike9000
Copy link
Author

vid.mov

@mikeymike9000
Copy link
Author

I believed this had also occurred in simulators and on devices for the past year or more but I could be mistaken.

@mikeymike9000
Copy link
Author

here's an example where it shows the issue including the hack where I select index 0 when avoiding the crash..

Screen.Recording.2022-12-13.at.3.57.33.PM.mov

@mikeymike9000
Copy link
Author

NOTE: the issue also occurs when my app is created as Ad Hoc or installed via TestFlight.

@mats-claassen
Copy link
Member

Instead of setting to 0, did you try just returning without doing anything?

@mikeymike9000
Copy link
Author

Returning without doing anything deselects the Segment's tab visually but doesn't actually hide the tab's content (see attached video). I will continue manually setting the index to 0 in case having it 'unset' while its content is accessible could cause other issues. My current hack/workaround is fine for me, I just wanted to let you know.

I'm also using Swift Package Manager, so what I've done is make a local copy of SegmentedRow.swift in my Xcode project, and renamed the file and class to be SegmentedRowCustom.

Screen.Recording.2022-12-14.at.11.24.48.AM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants