I have a simple OS X project ( in swift 2.0 and Xcode 7.0) and  that is 
supposed to open a .txt file and display the file’s contents in a document 
window.  For the most part, it works correctly, except that 
windowControllerDidLoadNib is called twice each time I chose OpenFile from the 
file menu.  This results in the contents of the file being displayed in my 
document window twice in succession.  The code is very similar to an 
objective-c project, which doesn’t do this, and I can’t see why this is 
happening.  Here’s an abbreviated version of windowControllerDidLoadNib:

override func windowControllerDidLoadNib(mySharedDocumentController: 
NSWindowController) {
        let myTextView: NSTextView = (self.TextView) as NSTextView
        
        let theWindow: NSWindow = myTextView.window! // NSTextView inherits 
from NSView, which can return a window
        
        // the next 2 lines are simply to test getting the name of the window; 
this is done correctly
        let theName: NSString? = theWindow.title
        print(“now at the top of windowControllerDidLoadNib \(theName)")
    
        scrollview.documentView = myTextView
        theWindow.contentView = scrollview

        theWindow.makeKeyAndOrderFront(nil)
        
        theWindow.makeFirstResponder(TextView)
        
        print("\n we are at the end of windowControllerDidLoadNib")
        
        updateView()  // the code of updateView has nothing to do with the 
problem; when it’s commented out, “now at the top of 
windowControllerDidLoadNib” still gets show twice

    }

Any suggestions why this might be happening would be greatly appreciated.

Boyd
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to