Search code examples
objective-cxcodecocoansdocument

How to set save notification when click close in document based application


I am doing a simple document based application. I've implemented readFromData and dataOfType function. Creating a newDocument and saveDocument are working. However, the question is how to set up save notification when user clicks Close. I add some data in my application and when I click close, it just directly close. There is no save notification. I think it was supposed to have it in document based application.

I tried windowWillClose:(NSNotification*)a, having an alertsheet. The alert comes and window closes immediately.

What I am missing?


Solution

  • Implement this kind of logic, and you will be done.

    - (BOOL)isDocumentEdited{
            if (somethingGotChanged){
                return YES;
            }
            else{
                return NO;
            }
            //or return somethingGotChanged; //*** make somethingGotChanged BOOL
        }
    

    Here, somethingGotChanged is a flag, which you have to set based on you editing on the data.