ios - How can a modal view controller be dismissed if the presenting view controller is changed? -
I am presenting a modal view controller on the iPad that changes the presented view controller during the presentation. For example:
- A visual controller VC presents the Model View Controller when the user selects a cell in the table view.
- The user has been designated a Model Model Controller and the second VC has been opened in the first place. Importantly, the visual controller is of the same type before changing the example.
- The modal view controller can not be dismissed or the exception
EXC_BAD_ACCESS is generated.
It is understandable to fail: Current view controller is no longer available. In fact, how would I reject this presented Model View Controller from a different Presented View Controller?
I have already code:
ViewController1.m
- (minus) showModalViewController: (UIViewController *) ViewController {UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController: ViewController]; Navigation Controller Model Presentation Style = UIModal Presentation Form Sheet; ViewController.navigationItem.rightBarButton = [[UIBarButton alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone Target: Self Operation: @selector (dismissModalViewController)]; [Self-present ViewController: Animation Navigation Controller: Yes Completed: Zero]; } - Dismiss (zero) Modelual controller {[Self-deleted view controller permission: Yes complete: zero]; [Unselect SelfTableViewValuePath: [SwavableView Index selected for text] Animated: Yes]; }
Thank you for your suggestions, but I used to solve this problem using the delegation The submitted view controller defines a delegate to inform when an action occurred
ChildViewControler.h:.
@protocol ChildViewControllerDelegate & LT; NSObject & gt; - (Zero) ChildView: (ChildViewController *) ChildView Selection ITM: (item *) items; @end
ChildViewController.m:
// interface @property (nonatomic, weak) id & lt; ChildViewControllerDelegate & gt; Representative; // In implementation - (zero) closeView: (item *) anItem {[self. Delegate childView: self didSelectItem: anItem]; }
ViewController1.m:
- (minus) showModalViewController: (UIViewController *) ViewController {UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController: ViewController ]; Navigation Controller Model Presentation Style = UIModal Presentation Form Sheet; viewController.navigationItem.rightBarButton = [[UIBarButton alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone goal: self action: @selector (dismissModalViewController)]; // different view controller types can be passed here so require Czech ... if (viewController.class == [ChildViewController square]) {((ChildViewController *) viewController) .delegate = self; [Self-present ViewController: Animation Navigation Controller: Yes Completed: Zero]; } - (zero) childview: (ChildViewController *) childView didelectItem: (item *) item {[self dismissViewControllerAnimated: Yes complete: zero]; [Unselect SelfTableViewValuePath: [SwavableView Index selected for text] Animated: Yes]; Take the necessary action with
Comments
Post a Comment