ios - UIActionSheet throws ViewController actionSheet:clickedButtonAtIndex -



ios - UIActionSheet throws ViewController actionSheet:clickedButtonAtIndex -

i using xcode 5.1.1 development purposes , using ios simulator test app. have action sheet has save, cancel , delete options. haven't yet coded action handling save , delete, tapping on cancel should go previous screen (i have used navigation controller move between screens). tapping on cancel, throws me "viewcontroller actionsheet:clickedbuttonatindex:]: message sent deallocated instance" error, not able solve. have hooked elements outlets/actions correctly. below code. please help. (i trying display action sheet when "return" button clicked. , in action sheet, when tap cancel, previous screen had displayed - guess can done dismissviewcontrolleranimated dismisses current controller , displays previous controller.)

-(ibaction)returnmodalaction:(id)sender { [self dismissviewcontrolleranimated: yes completion: null]; uiactionsheet *actionsheet = [[uiactionsheet alloc] initwithtitle:@"what want user values?" delegate:self cancelbuttontitle:nil destructivebuttontitle:@"delete" otherbuttontitles:@"save", nil]; actionsheet.cancelbuttonindex = [actionsheet addbuttonwithtitle:@"cancel"]; [actionsheet showinview:self.view]; } -(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex{ if (buttonindex == 2) { nslog(@"you have pressed %@ button", [actionsheet buttontitleatindex:buttonindex]); } }

on method returnmodalaction: dismissing view, garbage collector release references of self(the view controller) in memory that's why when seek to show action sheet [actionsheet showinview:self.view]; error because reference in memory doesn't exist.

so have perform [self dismissviewcontrolleranimated: yes completion: null]; when want display previous screen, in case on actionsheet:clickedbuttonatindex: method, based on index of button.

ios objective-c xcode

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -