1

I have an app where I'm attempting to add a sort of guided tour, where I lead the user from one feature to the next. What I want to do is to let the user interact with various interface elements and when they select the correct one the tour moves to the next step. I'm really having difficulty figuring out a way to do this. There are two ways I've been trying to approach it, but I can't quite figure out how to achieve either, nor can I be certain which would be better. The two options I've been working on are:

  1. Creating a subclass of UIView that would somehow transfer all user interactions through to the view that is directly behind it, but logs them so when the correct action is taken it can trigger the next step.

  2. Finding a way to add an observer to the UIResponder (typically a UIButton, but occasionally a UITableViewCell or other type) that will let the program know when touches have ended, which will allow the program to then check if the user performed the correct task.

Option 1 is simple enough if it's just a button, but seems more complicated when it's a UITableView or UIPickerView.

Option 2 is the one I'm leaning towards if only I could find a way to add an observer to a method (most likely touchesEnded:with:) in the same way they can be added to properties. That way, I could see when an interaction is made and check if it was the correct one. Of course, I could actually hard code moving to the next step into each method that is supposed to trigger it (if it meets the condition for being part of a guided tour), but that just seems like bad practice.

Does anyone have any suggestions? Is there a 'proper' way to do one of these things, or third option I should consider?

mightknow
  • 256
  • 3
  • 14
  • 1
    Could you check against the views tag to see if it was the view they were meant to click on? – Cameron Porter Dec 17 '18 at 02:52
  • This sounds like a perfect use-case for RxSwift+RxCocoa. Each button is just an observable of button events, but rather than having only your VC respond using IBOutlets, you can have any number of things subscribe themselves to the button's observable (such as your VC, your guided tour module, etc.) – Alexander Dec 17 '18 at 03:05
  • Cameron - the problem is how to call the function that will do the check, not necessarily what I'm checking against. – mightknow Dec 17 '18 at 06:21
  • Also, using `addTarget: action: for:` works if it's a `UIControl`, but there may also be some object types that are not `UIControl`. – mightknow Dec 17 '18 at 06:23

0 Answers0