Reputation: 5569
In Objective C (Cocoa) I have an app running with a modal sheet, but I want to allow the app to quit even when the sheet is displayed (contradicting the definition of modal I think, but I like the animated effect of modal sheets).
I'm already using the -setPreventsApplicationTerminationWhenModal
method and it works fine, but I'm wondering... is there any way to keep the close button enabled? The little circle usually red-colored close button that comes with all windows in the top left corner (side by side with minimize and maximize)? Right now it's completely disabled when the sheet is running, and it would be awesome if there is a way to enable it.
Thanks!
Upvotes: 2
Views: 1631
Reputation: 14427
Use a delegate method to close the Modal View. You declare the delegate on your modal view controller and that delegate method dismisses the ModalViewController
In the Modal ViewController Interface File:
@protocol MyViewControllerDelegate
-(void)dismissModal;
@end
Then declare the delegate as a class property in the Modal ViewController:
@property (nonatomic, retain) id <MyViewControllerDelegate> delegate;
Now, declare your parent ViewController as a proper delegate implementer for the Modal ViewController:
@interface MyParentViewController : UIViewController
Then in the calling (parent) ViewController implement the delegate method in the implementation file:
-(void)dismissModal
{
// Dismiss the Modal ViewController that we instantiated earlier
[self dismissModalViewControllerAnimated:YES];
}
That should do it. The advised way to handle this is through delegate methods (and delegate methods are so handy to use whenever a process in one controller needs to fire a method in another controller. It is well worth the time to get familiar with using delegates to get work done in Obj C
Upvotes: 0