Optional Cancel Button
nmccann opened this issue · comments
First off I would like to say thank you for this wonderful control, it does exactly what it says and does it well. The documentation in particular is impressive!
It would be nice if display of the Cancel button was optional, while the Delete button is useful in pretty much all scenarios, the Cancel button only makes sense when the view controller is presented modally. I know that you intend the view controller to be used modally so you likely don't see this as a problem.
Just to give you an idea of our use case, we embed the view controller in the very first screen that is shown after launching the app. Naturally in this case we have no where to go when Cancel is tapped, so displaying it could confuse users.
@Sun3 as a temporary solution I just used setValue:forKeyPath: to hide the cancel button. This also removes the "delete/backspace" functionality so it's not ideal.
I understand your use case, but as you stated, I have intended the view controller to be presented modally. Therefore, I currently have no plans to make the cancel button optional. However, you should be able to get the desired behaviour by modifying THPinView -updateBottomButton
like this:
- (void)updateBottomButton
{
if ([self.input length] == 0) {
[self.bottomButton setTitle:NSLocalizedStringFromTable(@"cancel_button_title", @"THPinViewController", nil)
forState:UIControlStateNormal];
[self.bottomButton removeTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
self.bottomButton.hidden = YES;
} else {
[self.bottomButton setTitle:NSLocalizedStringFromTable(@"delete_button_title", @"THPinViewController", nil)
forState:UIControlStateNormal];
[self.bottomButton removeTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
self.bottomButton.hidden = NO;
}
}
Version 1.2.2 now has a property to disable the cancel button.