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

Rotating device causing index out of range. #63

Closed
GeorgeA93 opened this issue Aug 17, 2016 · 4 comments
Closed

Rotating device causing index out of range. #63

GeorgeA93 opened this issue Aug 17, 2016 · 4 comments
Labels

Comments

@GeorgeA93
Copy link

The following is my implementation of the coachMarksForIndex data source function.

func coachMarksController(coachMarksController: CoachMarksController, coachMarksForIndex index: Int) -> CoachMark {
            let instruction = self.instructions[index]
            return coachMarksController.coachMarkForView(instruction.pointOfInterest)
}

As you can see I am accessing an array to determine the point of interest for each CoachMark.

This works as expected the first time you start the coachMarksController. However, during a rotation of the device (iPad Pro) the data source method fires, passing '-1' as the index. Obviously causing the index out of range exception.

Please note I am rotating the device after the coachMarksController finishes the animation; there are no coachMarks on screen.

I originally thought I was doing something wrong, however I am slightly confused as to why the data source function is firing when there are no coachMarks on screen.

I then realised that after running the coachMarkController once, I was not able to run it again. (I soon saw that you have fixed this #58 but not released it?)

Any ideas?

@ephread
Copy link
Owner

ephread commented Aug 18, 2016

Hello @GeorgeA93 thanks for reporting the issue! Indeed, #58 hasn't been released yet. Obviously, as you suspect, the dataSource methods aren't supposed to be called if coach marks are not showing. I'll look into it.

@ephread ephread added the bug label Aug 18, 2016
@GeorgeA93
Copy link
Author

Thanks for your reply. For anyone interested I am using the following work around to prevent the error:

func coachMarksController(coachMarksController: CoachMarksController, coachMarksForIndex index: Int) -> CoachMark {
    if index < 0 || index >= self.instructions.count {
            return coachMarksController.coachMarkForView()
    }
    let instruction = self.instructions[index]
    return coachMarksController.coachMarkForView(instruction.pointOfInterest)
}

This issue won't affect most users of this library because they are probably using a switch statement instead of accessing an array by index. (Assuming they have correctly implemented a default case in their switch statement)

@ephread
Copy link
Owner

ephread commented Aug 18, 2016

Great! 👏

By the way, I've suggested a workaround in the gitter chat for #58. Both issues will be fixed by 0.5.0 which should comme out before the end of august.

@ephread
Copy link
Owner

ephread commented Sep 4, 2016

Fixed by the big refactoring (c2cd243..7425eb7).

@ephread ephread closed this as completed Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants