Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6631067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:29:44+00:00 2026-05-25T22:29:44+00:00

I’m trying to change my windows content, from other class , that is subclass

  • 0

I’m trying to change my windows content, from other class , that is subclass of NSViewController.I’m trying code below, but it doesn’t do anything.

[NSApplication sharedApplication]mainWindow]setContentView:[self view]]; //code in NSViewController

[NSApplication sharedApplication]mainWindow] // returns null

I tried to add

[window makeMainWindow];

in App Delegate class, but it won’t help.

Did I miss something?

P.S. Also I’m using code below to call any delegate function in my class,

 [(appDelegate *) [[NSApplication sharedApplication]delegate]MyMethod];

but I wonder is there something better, wihtout importing delegate class. Something like this

[[NSApplication sharedApplication]delegate]MyMethod];

(it gives warning)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:29:45+00:00Added an answer on May 25, 2026 at 10:29 pm

    For the mainWindow method the docs say:

    This method might return nil if the application’s nib file hasn’t finished loading, if the receiver is not active, or if the application is hidden.

    I just created a quick test application and I placed the following code:

    NSLog(@"%@", [[NSApplication sharedApplication] mainWindow]);
    

    into my applicationDidFinishLaunching:aNotification method, and into an action method which I connected to a button in the main window of my application.

    On startup, the mainWindow was nil, but when I click the button (after everything is up and running and displayed), the mainWindow was no longer nil.

    NSApplication provides other methods which you may be useful to you:

    • - windows – an array of all the windows;
    • – keyWindow – gives the window that is receiving keyboard input (or nil);
    • – windowWithWindowNumber: – returns a window corresponding to the window number – if you know the number of the window whose contents you wish to replace you could use this;
    • – makeWindowsPerform:inOrder: – sends a message to each window – you could use this to test each window to see if it’s the one you are interested in.

    With regard to calling methods on the delegate, what you say gives a warning works fine for me. For example, this works with no warnings:

    NSLog(@"%@", [[[NSApplication sharedApplication]delegate] description]);
    

    What exactly is the warning you receive? Are you trying to call a method that doesn’t exist?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.