UIResponder Assistance - Method Not Called

438 views Asked by At

I have implemented HandOff using NSUserActivity, I initially implemented the following methods directly in my ViewController class, and all is working as expected.

-(void)updateUserActivityState:(NSUserActivity *)userActivity
-(void)restoreUserActivityState:(NSUserActivity *)activity
-(void)userActivityWasContinued:(NSUserActivity *)userActivity

As I'm planning to implement a number of Activity types I thought it would useful to create a separate class that would implement these methods instead of duplicating similar code, lets call this HandOffClass. This class is successfully creating the NSUserActivity and assigning it to the UserActivity property of a particular ViewController. This almost works but two of the above methods are implemented by UIResponder and are not being called when contained in the HandOffClass, if implemented directly in the ViewController all is working as expected.

-(void)updateUserActivityState:(NSUserActivity *)userActivity
-(void)restoreUserActivityState:(NSUserActivity *)activity

So my problem is my lack of understanding of how implement/subclass UIResponder methods

@interface HandOffClass : UIResponder  <NSUserActivityDelegate> 

Is my approach correct or is there a better way of approaching this, I'm guessing that my HandOffClass is not included in the responder chain?

Thanks for any help or guidance.

1

There are 1 answers

0
KirkSpaziani On

You might want to insert that object into the responder chain, so you're on the right track.

try something like this:

id nextResponder = [self nextResponder];
[self setNextResponder: _myCoolHandOffClass];
[_myCoolHandOffClass setNextResponder: nextResponder];

Remember to remove it!

Alternatively, use these "HandOffClasses" to contain the logic - and simply call them from your ViewController class. This way you have a bit less boiler plate (adding and removing from the responder chain), with the possible downside that your event will be handled by the ViewController even if you do nothing.