logo
down
shadow

Mac App Storyboard - Access Document in NSViewController


Mac App Storyboard - Access Document in NSViewController

By : user2952010
Date : November 18 2020, 03:49 PM
I wish this helpful for you I was just wrestling with this myself. I started with the standard Yosemite template and was trying to use [self.view.window.windowController document] in -viewDidLoad. At that point, self.view.window is nil, so there's no way to get to the document.
The trick is to wait until -viewWillAppear. By the time it is called, self.view.window is populated and the document is available.
code :


Share : facebook icon twitter icon
How to access the NSView from a NSViewController contained in another NSViewController

How to access the NSView from a NSViewController contained in another NSViewController


By : Tony Scheller
Date : March 29 2020, 07:55 AM
will be helpful for those in need Turns out the sub view controllers were never loaded, only initialized. I had to access the view in the base view controller to load the view controllers, and then their views.
Set representedObject on an NSViewController in a document-based OS X application

Set representedObject on an NSViewController in a document-based OS X application


By : user3786119
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I was able to set the view controller's represented object by overriding the NSViewController's viewWillAppear method, which appears to be called after the document instance is set as the window document.
code :
- (void)viewWillAppear {
    [super viewWillAppear];

    // Set up the document as the data source
    NSLog(@"viewWillAppear");
    NSWindow *myWindow = [[self view] window];
    NSWindowController *myWindowController = [myWindow windowController];
    CharacterSheetDocument *myDocument = [myWindowController document];
    [self setRepresentedObject: [myDocument characterData]];
}
Replace NSViewController under Swift2 Storyboard MAC OSX

Replace NSViewController under Swift2 Storyboard MAC OSX


By : mayank bhandari
Date : March 29 2020, 07:55 AM
hop of those help? You need to use a custom segue class (or possibly NSTabViewController if it’s enough for your needs). Set the segue’s type to Custom, with your class name specified:
code :
class ReplaceSegue: NSStoryboardSegue {
    override func perform() {
        if let src = self.sourceController as? NSViewController,
           let dest = self.destinationController as? NSViewController,
           let window = src.view.window {
            // this updates the content and adjusts window size
            window.contentViewController = dest
        }
    }
}
class ReplaceSheetSegue: NSStoryboardSegue {
    override func perform() {
        if let src = self.sourceController as? NSViewController,
           let dest = self.destinationController as? NSViewController,
           let window = src.view.window {
            // calculate new frame:
            var rect = window.frameRectForContentRect(dest.view.frame)
            rect.origin.x += (src.view.frame.width - dest.view.frame.width) / 2
            rect.origin.y += src.view.frame.height - dest.view.frame.height
            // don’t shrink visible content, prevent minsize from intervening:
            window.contentViewController = nil
            // animate resizing (TODO: crossover blending):
            window.setFrame(window.convertRectToScreen(rect), display: true, animate: true)
            // set new controller
            window.contentViewController = dest
        }
    }
}
Mac OSX Storyboard : communicate between NSViewController

Mac OSX Storyboard : communicate between NSViewController


By : Jagat Bandhu Sahoo
Date : March 29 2020, 07:55 AM
hope this fix your issue I managed to get what i want by adding the following code in AppDelegate.m :
code :
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    //
    NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main"
                                                            bundle:[NSBundle mainBundle]];

    self.windowController = [storyboard instantiateControllerWithIdentifier:@"windowController"];
    self.window = self.windowController.window;

    self.splitViewController = (NSSplitViewController*)self.windowController.contentViewController;
    NSSplitViewItem *item0 = [self.splitViewController.splitViewItems objectAtIndex:0];
    NSSplitViewItem *item1 = [self.splitViewController.splitViewItems objectAtIndex:1];
    self.leftViewController = (OMNLeftViewController*)item0.viewController;
    self.rightViewController = (OMNRightViewController*)item1.viewController;

    [self.window makeKeyAndOrderFront:self];
    [self.windowController showWindow:nil];
}
    self.leftViewController.rightView = self.rightViewController;
NSViewController-Close window-Swift-Storyboard

NSViewController-Close window-Swift-Storyboard


By : Parminder Kaur
Date : March 29 2020, 07:55 AM
it should still fix some issue I had same question. And your code was very helpful for me.
Then I checked "VC <- view <- window <- windowController" out in NS Lib. hierarchey has.
Related Posts Related Posts :
  • App crashes while converting to Objective-C ARC
  • When updating the TestFlight SDK do you need to delete the old version?
  • How to read file by sector,and not rely on the OS cache in Cocoa
  • Convert from NStimeInterval to CMTime accurately
  • How can I continue my count from the correct spot once I load the saved count?
  • instance method 'connect:' not found (return type defaults to 'id'
  • Does an object initialize automatically if it is the synthesized property of another object?
  • What reasons are there to pass an argument to an initializer in objective C?
  • NSLogging UILabel's text outputs null
  • undefined reference to '__objc_class_name_Fraction'
  • Move UIView above UITableView when user Scrolls Down
  • adding object to nsmutablearray with custom delegate function giving error
  • Cocoa editing NSBezierPath
  • Perform a action on specific time using Parse
  • Objective-C: How to convert json value to BOOL?
  • How to make an int counter for the days
  • Assigning Label Value with Selected Table View Cell
  • SpriteKit - Preloader using GCD
  • Can dependency injection like Typhoon replace multiple singletons?
  • Objective C - How to determine if a folder is a package?
  • How can one draw a background in the elastic portion of an NSScrollView?
  • A solution for my issue with sending some info from an array to Parse
  • Swift Extension fails adding overloaded methods to Objective-C class
  • Determine if key is incorrect with CCCrypt kCCOptionPKCS7Padding-Objective C
  • PQgetResult always returns NULL
  • self.navigationController? is nil when pushing from a objective-c viewController to a Swift ViewController
  • Where to add subViews that I want floating in an NSScrollView using AutoLayout?
  • 'User' in 'User-defined classes'
  • How to get value of a key in NSDictionary?
  • Adding Border Line to UITableView in StoryBoard
  • Objective c, reposition a view above the keyboard in one single animation
  • Dismiss modal segue
  • Error message is saying my data is NULL - NSKeyedUnArchiver - I've followed all the steps - still won't work
  • Remove apostrophe in CFStringTransform results
  • Label showing wrong values while NSLog shows the right ones in SpriteKit
  • How to work with locally modified Cocoapod which don't include podspec?
  • What does kCGWindowSharingState actually do?
  • It is possible to copy a CFTypeRef?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org