ios - Setting the delegate for UIAlertView -
i’m updating code new uialertcontroller
, since there lot of alerts throughout project, pulled alert code own class. uialertcontroller
works perfectly, having problem getting old uialertview
work.
if utilize self delegate, code crashes. suspect because object gone time delegate called. if utilize self.navigationcontroller
, code doesn’t crash delegate doesn’t button click. have same delegate method in calling class , doesn’t called either.
i tried making showalert method class method, didn’t work. suspect may need set uialertview
delegate calling class, have no thought how that.
@implementation showsystemalert - (instancetype)initwithnavigatiocontroller:(uinavigationcontroller *)navigationcontroller withmanagedobjectcontext:(nsmanagedobjectcontext *)context withscorekeeper:(scorekeeper *)scorekeeper withwordlist:(wordlist *)wordlist { self = [super init]; if (self) { _navigationcontroller = navigationcontroller; _mobjcontext = context; _scorekeeper = scorekeeper; _wordlist = wordlist; } homecoming self; } - (void)showalert { if (system_version_greater_than_or_equal_to(@"8.0")) { // code uialertcontroller goes here [self.navigationcontroller presentviewcontroller:alert animated:true completion:nil]; } else { uialertview *alert = [[uialertview alloc] initwithtitle:@"'only show favorites'\nturned off" message:@"awe looked words in categories selected did not find any. turned off 'only show favorites' , found words." self.navigationcontroller cancelbuttontitle:@"settings" otherbuttontitles:@"continue", nil]; [alert show]; } } #pragma mark - no words - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { nslog(@"in alertview delegate"); if (buttonindex == 0) { nslog(@"cancel buttonpressed on no words"); prefstableviewcontroller *ptvc = [[prefstableviewcontroller alloc] initwithwordlist:self.wordlist]; [self.navigationcontroller pushviewcontroller:ptvc animated:yes]; } } @end
under ios8, please alter delegate method clickedbuttonatindex
diddismisswithbuttonindex
change line to
-(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {
with this
-(void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {
you should find solve crash.
i hope helps.
ios objective-c delegates
No comments:
Post a Comment