this question has answer here:
hi new xcode n objective-c need on one. have no button uialertview, gets dismissed on click on itself.but want dismiss on click of outside alert box not inside. thanks
//generating alertview no button +(void) showalertnobuttons:(nsstring*)title text:(nsstring*)text{ uialertview* alertview = [[uialertview alloc] initwithtitle:title message:text delegate:self cancelbuttontitle:nil otherbuttontitles:nil]; uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(dismissalert:)]; alertview.delegate=self; [alertview addgesturerecognizer:singletap]; [alertview setmultipletouchenabled:yes]; [alertview setuserinteractionenabled:yes]; [alertview show]; } // +(void)dismissalert:(uitapgesturerecognizer *)gesture { uialertview* alertview =(uialertview *)gesture.view; [alertview dismisswithclickedbuttonindex:0 animated:yes]; }
you need call - (void)dismisswithclickedbuttonindex:(nsinteger)buttonindex animated:(bool)animated
when tap anywhere else
this piece of code handle tap
- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { [self dismisswithclickedbuttonindex:index animated:yes]; }
Comments
Post a Comment