0
votes

I am launching an UIActionsheet in my app.On rotation, the action sheet is not centrally aligned ,so On rotation I dismiss the actionsheet and reOpen it using

[actionsheet dismissWithClickedButtonIndex:-1 animated:NO];
[actionsheet showInView:self.view];

But the problem is in iOS6 it throws the following error

* Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with <_UIActionSheetHostingController: 0x18615830>. Clear this association before associating this view with <_UIActionSheetHostingController: 0xe0f28b0>.'

I tried using:

[actionsheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];

but still I get the same error.

Everything works fine on iOS7.

I have searched a lot but fixes are mostly done through XIBs.I want to solve it programmatically. Does anyone has any idea about this?

1

1 Answers

3
votes

EDIT : Reason for this issue is removing and showing cannot be done at a same time

[actionsheet dismissWithClickedButtonIndex:-1 animated:NO];
//adding some delay as dismissing one actionsheet and presenting actionsheet after some time
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:0.3];

Add these below method :

-(void)showActionSheet
{
  [actionsheet showInView:self.view];
}