objective c - Set delegate:self.delegate in an alertView where self.delegate implements UIAlertViewDelegate protocol -
in viewcontroller have implemented uialertviewdelegate , in model have method creates uialertview delegate set self.delegate instance of viewcontroller. seek phone call willpresentalertview (in model):
uialertview *alert = [[uialertview alloc] initwithtitle:@"invalid operation" message:@"cannot split 0!" delegate:self.delegate cancelbuttontitle:@"cancel" otherbuttontitles:@"undo division",nil]; [self.delegate willpresentalertview:alert];
the willpresentalertview implemented in viewcontroller this:
- (void)willpresentalertview:(uialertview *)alertview { [alertview show]; }
i error thread 1:exc_bad_access (code=2,adress=0xbf7fff6c) when calling [alert show]
.
if set delegate nil
or self works fine, want phone call alertview:alertview clickedbuttonatindex:buttonindex
when press button on alert, doesn't work delegate set nil or self. viewcontroller implements these methods, why should self.delegate, or?
i want model invoke alert, want viewcontroller handle alert methods such alertview:alertview clickedbuttonatindex:buttonindex
.
how can done?
it should self [self willpresentalertview:alert]
uialertview *alert = [[uialertview alloc] initwithtitle:@"invalid operation" message:@"cannot split 0!" delegate:self //self cancelbuttontitle:@"cancel" otherbuttontitles:@"undo division",nil]; [self willpresentalertview:alert];//self 1 time again
objective-c xcode delegates uialertview uialertviewdelegate
No comments:
Post a Comment