Reputation: 4378
I have a view controller in my iOS app during registration that a user has the option of skipping. However, if they start the step, they either have to finish it or hit undo, so that partial information isn't saved. To ensure this, I hide the nav bar button that goes to the next screen. At first, I have the text say "SKIP", then when you start entering info, it disappears, and once you've entered in enough information, the title should change to "NEXT". It works backwards, as well. You could enter enough information for "NEXT" to appear, then hit undo, the button disappears, keep hitting undo, and the button should say "SKIP" again.
The problem is that when the button reappears, it still has the old title for a split second before changing to the new title. So it'll say "SKIP", the user starts entering info, it disappears, the user enters in all of the info, and it reappears, saying "SKIP" for a split second, then changing to "NEXT".
Here is the function that gets called when info is updated, checking to see what the button should display as:
-(void)checkValid
{
if( /*starting condition*/ )
{
[_nextButton setTitle:@"SKIP" forState:UIControlStateNormal];
[_nextButton setTitle:@"SKIP" forState:UIControlStateDisabled];
[_nextButton setTitle:@"SKIP" forState:UIControlStateSelected];
[_nextButton setTitle:@"SKIP" forState:UIControlStateHighlighted];
[_nextBarButtonItem setEnabled:YES];
[_nextButton setHidden:NO];
}
else if( /* complete condition */ )
{
[_nextButton setTitle:@"NEXT" forState:UIControlStateNormal];
[_nextButton setTitle:@"NEXT" forState:UIControlStateDisabled];
[_nextButton setTitle:@"NEXT" forState:UIControlStateSelected];
[_nextButton setTitle:@"NEXT" forState:UIControlStateHighlighted];
[_nextBarButtonItem setEnabled:YES];
[_nextButton setHidden:NO];
}
else /* in between condition */
{
[_nextButton setHidden:YES];
[_nextBarButtonItem setEnabled:NO];
}
}
_nextButton is the custom UIButton that I dragged onto the nav bar in the IB. _nextBarButtonItem is the UIBarButtonItem that the UIButton appears under in the view hierarchy. I had initially just set UIControlStateNormal 's title, but figured that maybe as the button appeared it was in a different state, so I tried adding every state...
Any ideas what could be going wrong? I'm not changing the title anywhere else that could be conflicting.
I appreciate any tips.
edit - I've tried changing it so that I'm only changing _nextButton's hidden attribute, so _nextBarButtonItem's enabled attribute is always on. This allows for the same functionality (since _nextButton is hidden, you can't press it), but it's still showing the incorrect text for just a split second. The code was exactly the same as what I previously posted, except all of the [_nextBarButtonItem setHidden:] calls are commented out.
Upvotes: 2
Views: 129
Reputation: 84
Okay, before we try anything too drastic, here are some non-coding solutions (I'm sure you've tried these, but it's never too late to give one of these another shot. :D)
Sorry for the basic solution. For me, personally, it's difficult to solve problems without the actual file on hand. Sorry!
Upvotes: 1