Loading View in Placeholder upon startup

  • Hello everyone,

    I have a document-based application which users a placeholder view
    that loads a view from MyDocument.nib. When the application loads the
    window is blank. I want to be able to view the default view when i
    start up the application, any ideas?

    Here is my code to update the view:

    - (void)setDocumentView:(id)sender {
    NSView *view = documentPlaceholderView;
    if (sender) {
      NSString *identifier = [sender itemIdentifier];
      if ([identifier isEqualToString:SQLViewToolbarItem])
      view = sqlModeView;
      else if ([identifier isEqualToString:TSDataViewToolbarItem])
      view = dataModeView;
      else;
    }

    NSWindow *window = [self window];
    if ([window contentView] == view)
      return;
    NSRect windowRect = [window frame];

        [view setHidden:YES];
        [window setFrame:windowRect display:YES animate:NO];
        [window setContentView:view];
        [view setHidden:NO];
    }

    I tried to use the awakeFromNib method to load this by calling
    [ApplicationController setDocumentView:SQLViewToolbarItem]; but this
    didn't work. Then I tried to use windowDidLoad and that didn't work...

    I can't figure it out.

    Thanks,
    Rick
  • The cross-post to xcode-users was unnecessary; I've removed it.

    On 25 Nov 2007, at 9:25 PM, Rick Langschultz wrote:

    > - (void)setDocumentView:(id)sender {
    > NSView *view = documentPlaceholderView;
    > if (sender) {
    > NSString *identifier = [sender itemIdentifier];
    > if ([identifier isEqualToString:SQLViewToolbarItem])
    > view = sqlModeView;
    > else if ([identifier isEqualToString:TSDataViewToolbarItem])
    > view = dataModeView;
    > else;
    > }
    >
    ...
    >
    > [window setContentView:view];
    ...
    > I tried to use the awakeFromNib method to load this by calling
    > [ApplicationController setDocumentView:SQLViewToolbarItem]; but this
    > didn't work. Then I tried to use windowDidLoad and that didn't work...

    I haven't picked through all your code, but it appears
    SQLViewToolbarItem (which you send as sender) is an NSToolbarItem (you
    send sender itemIdentifier, and you don't report that sender doesn't
    find that method). But you treat sender as an NSString (you pass it in
    isEqualToString:).  The isEqualToString: returns NO. So view, as of
    the setContentView:, is documentPlaceholderView.

    I assume this is what you mean by "didn't work," though you don't say
    what you mean by that.

    — F
  • Thank you for writing. I am looking through my code now to try to
    resolve this issue.

    Thank you for your response.

    On Nov 26, 2007, at 12:00 PM, Fritz Anderson wrote:

    > The cross-post to xcode-users was unnecessary; I've removed it.
    >
    > On 25 Nov 2007, at 9:25 PM, Rick Langschultz wrote:
    >
    >> - (void)setDocumentView:(id)sender {
    >> NSView *view = documentPlaceholderView;
    >> if (sender) {
    >> NSString *identifier = [sender itemIdentifier];
    >> if ([identifier isEqualToString:SQLViewToolbarItem])
    >> view = sqlModeView;
    >> else if ([identifier isEqualToString:TSDataViewToolbarItem])
    >> view = dataModeView;
    >> else;
    >> }
    >>
    > ...
    >>
    >> [window setContentView:view];
    > ...
    >> I tried to use the awakeFromNib method to load this by calling
    >> [ApplicationController setDocumentView:SQLViewToolbarItem]; but
    >> this didn't work. Then I tried to use windowDidLoad and that didn't
    >> work...
    >
    > I haven't picked through all your code, but it appears
    > SQLViewToolbarItem (which you send as sender) is an NSToolbarItem
    > (you send sender itemIdentifier, and you don't report that sender
    > doesn't find that method). But you treat sender as an NSString (you
    > pass it in isEqualToString:).  The isEqualToString: returns NO. So
    > view, as of the setContentView:, is documentPlaceholderView.
    >
    > I assume this is what you mean by "didn't work," though you don't
    > say what you mean by that.
    >
    > — F
  • This issue has been resolved by copying some code from my
    setDocumentView method to awakeFromNib;

    Thanks for all of your help.

    On Nov 26, 2007, at 12:51 PM, Rick Langschultz wrote:

    > Thank you for writing. I am looking through my code now to try to
    > resolve this issue.
    >
    > Thank you for your response.
    >
    >
    > On Nov 26, 2007, at 12:00 PM, Fritz Anderson wrote:
    >
    >> The cross-post to xcode-users was unnecessary; I've removed it.
    >>
    >> On 25 Nov 2007, at 9:25 PM, Rick Langschultz wrote:
    >>
    >>> - (void)setDocumentView:(id)sender {
    >>> NSView *view = documentPlaceholderView;
    >>> if (sender) {
    >>> NSString *identifier = [sender itemIdentifier];
    >>> if ([identifier isEqualToString:SQLViewToolbarItem])
    >>> view = sqlModeView;
    >>> else if ([identifier isEqualToString:TSDataViewToolbarItem])
    >>> view = dataModeView;
    >>> else;
    >>> }
    >>>
    >> ...
    >>>
    >>> [window setContentView:view];
    >> ...
    >>> I tried to use the awakeFromNib method to load this by calling
    >>> [ApplicationController setDocumentView:SQLViewToolbarItem]; but
    >>> this didn't work. Then I tried to use windowDidLoad and that
    >>> didn't work...
    >>
    >> I haven't picked through all your code, but it appears
    >> SQLViewToolbarItem (which you send as sender) is an NSToolbarItem
    >> (you send sender itemIdentifier, and you don't report that sender
    >> doesn't find that method). But you treat sender as an NSString (you
    >> pass it in isEqualToString:).  The isEqualToString: returns NO. So
    >> view, as of the setContentView:, is documentPlaceholderView.
    >>
    >> I assume this is what you mean by "didn't work," though you don't
    >> say what you mean by that.
    >>
    >> — F

previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today