ios - alertViewShouldEnableFirstOtherButton not called -
i want show uialertview textfield. , if user has not entered valid emai id ok button of uialertview disable.
i know how show uialertview , disable uialertview ok button ..
my problem -(bool)alertviewshouldenablefirstotherbutton:(uialertview *)alertview
not called thats why button enabled.
but when user press ok button
- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex
is called.
here code ,
-(ibaction)forgotpassbtnclicked:(id)sender { uialertview *alertview=[[uialertview alloc]initwithtitle:@"" message:@"" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alertview setalertviewstyle:uialertviewstyleplaintextinput]; uitextfield *textfield=[alertview textfieldatindex:0]; textfield.placeholder=@"enter email id"; [alertview show]; } #pragma mark alertview delgate - (bool)alertviewshouldenablefirstotherbutton:(uialertview *)alertview { uitextfield *text1=[alertview textfieldatindex:0]; bool flag=[self validateemail:text1.text]; return flag; } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { } #pragma mark email validation - (bool) validateemail: (nsstring *) email { nsstring *emailregex = @"[a-z0-9a-z._%+-]+@[a-za-z0-9.-]+\\.[a-za-z]{2,4}"; nspredicate *emailtest = [nspredicate predicatewithformat:@"self matches %@", emailregex]; // return 0; return [emailtest evaluatewithobject:email]; }
i don't understand doing wrong?..
thanks in advance...
uialertviewdelegate
documentation says alertviewshouldenablefirstotherbutton:
method,
sent delegate determine whether first non-cancel button ion alert should enabled.
you creating alert cancel button @"ok"
, since non-cancel buttons nil
method not getting called. instead try following,
uialertview *alertview=[[uialertview alloc]initwithtitle:@"" message:@"" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"ok", nil];
also, user should have option cancel alert without having enter text. user experience have cancel button.
Comments
Post a Comment