ios - show a button through alertview button in view controller -
i have alertview appears every time when app launched. want show button on viewcontroller when clicked show button of alertview when clicked on cancel button button not show. using code this.
- (void )alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { if (buttonindex == 0) { viewcontroller *controller = [[viewcontroller alloc]init]; controller.button.hidden= no; }
and in viewcontroller create outlet of button. , done below code in view did load of view controller unable show button
- (void)viewdidload { [super viewdidload]; self.button.hidden = yes; }
uialertview
deprecated. use uialertcontroller
preferredstyle of uialertcontrollerstylealert
instead.
https://developer.apple.com/library/ios/documentation/uikit/reference/uialertcontroller_class/
- (void)viewdidload { [super viewdidload]; //init hide button self.button.hidden = yes; uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:@"title" message:nil preferredstyle:uialertcontrollerstylealert]; uialertaction *ok = [uialertaction actionwithtitle:@"ok" style:uialertactionstyledefault handler:^(uialertaction *action) { //show button self.button.hidden = no; }]; uialertaction *cancel = [uialertaction actionwithtitle:@"cancel" style:uialertactionstylecancel handler:^(uialertaction *action) { //hide button self.button.hidden = yes; }]; [alert addaction:ok]; [alert addaction:cancel]; [self presentviewcontroller:alert animated:yes completion:nil]; }
your current code can that:
delegate.m
viewcontroller *controller = [[viewcontroller alloc]init]; uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:@"title" message:nil preferredstyle:uialertcontrollerstylealert]; uialertaction *ok = [uialertaction actionwithtitle:@"ok" style:uialertactionstyledefault handler:^(uialertaction *action) { //show button controller.button.hidden = no; }]; uialertaction *cancel = [uialertaction actionwithtitle:@"cancel" style:uialertactionstylecancel handler:^(uialertaction *action) { //hide button controller.button.hidden = yes; }]; [alert addaction:ok]; [alert addaction:cancel]; [window.rootviewcontroller presentviewcontroller:alert animated:yes completion:nil];
viewcontroller.m
- (void)viewdidload { [super viewdidload]; //self.button.hidden = no; remove line }
Comments
Post a Comment