I have some kind of feed with story elements which can be liked, just like Facebook has.
My first step was just using the story model object to get the liked status and show that in a CKButtonComponent. The problem with that solution is that the button does not represent the expected new like status fast enough. Instead I'm making a web service call, which response changes the story and then the button gets changed.
To get a faster button state change, I build a CKComponentController for that CKComponent which updates a state of the component when the button gets pressed:
- (void)toggleLike {
[self.component updateState:^(id oldState){
if ([oldState integerValue] == LikeComponentStateInitial || [oldState integerValue] == LikeComponentStateNotLiked) {
return @(LikeComponentStateLiked);
}
return @(STGLikeComponentStateNotLiked);
}];
[WebService toggleLikeForStory:...];
}
Additionally I'm making a web service call. The problem with that solution is that when I press the like-Button multiple times fast enough the app crashes with the message:
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unhandled component action toggleLike following responder chain nil'
The crash happens at an Assert in void CKComponentActionSend(CKComponentAction action, CKComponent *sender, id context, CKComponentActionSendBehavior behavior)
in the CKComponentAction class. I don't know why this happens only when i hit the button fast enough multiple times. It seems to have something to do with reload of all components which happens when the new story data get saved from the web service response. The reload of all components and at the same time the CKButtonComponent getting the touch event seems to lead to the crash.
The CKComponentAction of the CKButtonComponent is the described CKComponentController method toggleLike
.
So what would be a good solution in this case? Is there a way to do this without changing the story model object?
I have also the feeling that my approach to use the state to override some model data (like status) is generally not really a good idea.