ios - alertView:(UIAlertView *) alertView method not working in Appdelegate -



ios - alertView:(UIAlertView *) alertView method not working in Appdelegate -

i had set uialertview in appdelegate.m file.

but when take button on alert view.

-(void) alertview:(uialertview *) alertview clickedbuttonatindex:(nsinteger)buttonindex

was not working.

i had set uialertviewdelegate in appdelegate.h file.

and appdelegate.m

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions: (nsdictionary *)launchoptions { [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(reachabilitychanged:) name:kreachabilitychangednotification object:nil]; nsstring *remotehostname = reachability_host; _hostreachability = [reachability reachabilitywithhostname:remotehostname]; [_hostreachability startnotifier]; homecoming yes; } - (void) reachabilitychanged:(nsnotification *)note { if( [reachability isexistnetwork] == notreachable) { uialertview *alertview = [[uialertview alloc] initwithtitle:nil message:@"my message" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:@"set",nil]; [alertview show]; } } -(void) alertview:(uialertview *) alertview clickedbuttonatindex:(nsinteger)buttonindex { switch (buttonindex) { case 0: nslog(@"ok!"); break; // set case 1: nslog(@"set!"); nsurl*url=[nsurl urlwithstring:@"prefs:root=wifi"]; [[uiapplication sharedapplication] openurl:url]; break; } }

but

-(void) alertview:(uialertview *) alertview clickedbuttonatindex:(nsinteger)buttonindex

was not come in method.

have know happened? thanks.

your code doesn't correctly set delegate of alert view.

you need alter next line delegate appropriate object (eg, self):

uialertview *alertview = [[uialertview alloc] initwithtitle:nil message:@"my message" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:@"set",nil];

ios objective-c uialertview appdelegate uialertviewdelegate

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -