2
votes

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!

1
As long as modal window is attached to parent window, parent window might not be an active window.So, just check it out.boom
@iSight: True... I'm new to cocoa, so I have to ask: what do you mean by "check it out"? Just to check it out in common day sense or is there a programmatic meaning behind it?Vervious
@Nano8Blazex As to my knowledge, the modal window is attached to parent window, the modal window becomes the key window, and until it resigns from being key window the parent window can never become a key window, and i cannot find such usage as you need till now. Instead you can call another window for modal window.boom
@iSight: Thanks for responding. I understand all that, except when you say "you can call another window for modal window"? You mean... Since... I'm confused :)Vervious
I mean instead for calling modal for sheet call another window.boom

1 Answers

0
votes

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