ios - Objective-C UIKit UIAlertViewDelegate not called -


i begin learn objective-c uikit , ran problem.uialertviewdelegate not called.can tell me why? thank you!

#import <foundation/foundation.h> #import <uikit/uikit.h> @interface alertlearn : nsobject <uialertviewdelegate> -(void) showalerttest; - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex; @end  #import "alertlearn.h" #import <uikit/uikit.h>  @implementation alertlearn  -(void) showalerttest{     uialertview * alertview = [[uialertview alloc] initwithtitle:@"alert" message:@"alert test" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"ok", nil];     [alertview show];  } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{      nslog(@"clickedbuttonatindex = %ld",buttonindex );     nsstring *buttontitle = [alertview buttontitleatindex:buttonindex];     nslog(@"clickedbuttonatindex title = %@",buttontitle); } @end 

this because assigning alert view in stricter life span should be, try making alert ivar or property , try again.

@interface alertlearn : nsobject <uialertviewdelegate> { uialertview * alertview; } -(void) showalerttest; - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex; @end ... -(void) showalerttest{     alertview = [[uialertview alloc] initwithtitle:@"alert" message:@"alert test" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"ok", nil];     [alertview show];  } 

and remove definition showalerttest method.

p.s.: please note type of showing alert view deprecated of ios 8, should use uialertcontroller instead, if reason need support ios 7 , below, well, should make strong pointer alert.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -