Reputation: 4490
Can anyone help me in preventing dismissal of alertview on its button click event??
I have a textview as a subview of my alertView and i dont want to dismiss it if textview's value is nil.
Upvotes: 3
Views: 2080
Reputation: 2160
As this is very old question,but I got one solution and though of posting if any other developer need in near future.
Implement protocol methods in .h file
In order to respond to button taps in our UIAlertView, we will use the – alertView:clickedButtonAtIndex: protocol method as
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
}
//Now below code will check if uitextfield value.
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] > 0)
{
//text field value is greater than zero ,then Done button will appear as blue,or else it will be blurred
return YES;
}
else
{
return NO;
}
}
Alternately, there is a much faster approach:
return [inputText length] ? YES : NO;
The does the same thing as the if statement
does.
Upvotes: 4
Reputation: 3400
i'm not sure you can.
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
is the only option available on callBack. And there's still at least one active button.
If you really need that specific behavior, try reimplementing your own UIAlertView
Upvotes: 1
Reputation: 4746
That might be against HIG Guidelines to NOT to dismiss an UIAlertView.
WORKAROUND : I don't know what goes on in your app, but to acheive this thing, what you could do is dismiss the AlertView and then check if textView's text is set or not. If it is set to nil, then bring up the alertview again!
Upvotes: 3