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 8660007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:08:54+00:00 2026-06-12T16:08:54+00:00

I am very much new to OSX development. Consider this as my first app.

  • 0

I am very much new to OSX development. Consider this as my first app. I want to display a sheet when a button is clicked on the main window. I am using Nib

Following is my code for .h file

#import <Foundation/Foundation.h>
#import "WebKit/Webkit.h"

@interface MainViewObject : NSObject
- (IBAction)accountButtonPressed:(id)sender;
- (IBAction)cancelSheetButtonPressed:(id)sender;

.m file as follows

#import "MainViewObject.h"
@implementation MainViewObject

- (IBAction)accountButtonPressed:(id)sender {
    [NSApp beginSheet:self.accountSheet
   modalForWindow:[mainWindowView window]
    modalDelegate:nil
   didEndSelector:nil
      contextInfo:nil];

[NSApp runModalForWindow:self.accountSheet];

[NSApp endSheet:self.accountSheet];
[self.accountSheet orderOut:self];
}

- (IBAction)cancelSheetButtonPressed:(id)sender {
// Return to normal event handling
[NSApp endSheet:self.accountSheet];
// Hide the sheet
[self.accountSheet orderOut:sender];
}

When I run the app I get something like this:

https://i.stack.imgur.com/EKxQn.png

I am stuck and I have no idea what wrong in this. I am not able to get the sheet and the not able to even close the app. I have referred to some examples on internet.

  • 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-06-12T16:08:55+00:00Added an answer on June 12, 2026 at 4:08 pm
    - (IBAction)accountButtonPressed:(id)sender {
        [NSApp beginSheet:self.accountSheet
       modalForWindow:[mainWindowView window]
        modalDelegate:nil
       didEndSelector:nil
          contextInfo:nil];
    
        [NSApp runModalForWindow:self.accountSheet];
    
        [NSApp endSheet:self.accountSheet];
        [self.accountSheet orderOut:self];
    
    }
    

    Wow, looking at that, it’s no surprise the screenshot looks as it is.

    Let’s walk through that one line at a time. When you click the Accounts button, you’re doing 4 things immediately in succession:

    1. You’re telling the application to begin showing the sheet attached to your main window. This is OK, and is actually the only code you want in that accountButtonPressed: method.

    2. Right after beginning that sheet, you tell the application you want to also show that sheet all by itself (not attached to any windows but right in the middle of the screen), in an application-modal fashion, which blocks all other events from being processed in the application. In other words, this line doesn’t really make sense. You either show a window as a sheet in a “document-modal” fashion (which only ties up the window that the sheet is attached to) or in an “application-modal” fashion, but not both at the same time. 😉

    3. Immediately after having just shown the sheet, you tell NSApp to stop showing the sheet. Now, you do want to do this eventually, but dismissing the sheet 0.0005 seconds after having just shown it will likely leave your users a little frustrated.

    4. You now tell the sheet to hide itself. This needs to be done from your didEndSelector: method, which brings us to the problems in your first method.

    –

    [NSApp beginSheet:self.accountSheet
       modalForWindow:[mainWindowView window]
        modalDelegate:nil
       didEndSelector:nil
          contextInfo:nil];
    

    This is good but read the documentation for beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: and also the Sheet Programming Topics: Using Custom Sheets. (The Companion guides links at the top of Class Reference pages are especially helpful for learning how to use the APIs in the real world. They were extremely helpful when I was learning).

    Specifying nil for the modalDelegate: means you don’t have anything that’s waiting to be notified about when the sheet has stopped being shown (this happens when you call [NSApp endSheet:sheet]). You also haven’t specified the @selector you want called when the sheet is ended. A selector is kind of like a function, aka a “method”.

    Your code should look something like this:

    @implementation MDAppDelegate
    
    - (IBAction)showSheet:(id)sender {
        [NSApp beginSheet:self.sheet
           modalForWindow:self.window
            modalDelegate:self
           didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
              contextInfo:NULL];
    }
    
    - (IBAction)cancel:(id)sender {
        [NSApp endSheet:self.sheet];
    }
    
    - (IBAction)ok:(id)sender {
        [NSApp endSheet:self.sheet];
    }
    
    - (void)sheetDidEnd:(NSWindow *)sheet
                returnCode:(NSInteger)returnCode
                   contextInfo:(void *)contextInfo {
        [sheet orderOut:nil];
    }
    @end
    

    In this example, you click the Show Sheet button, and the sheet starts being shown attached to the main window. In the sheet, there is a Cancel and an OK button, which both call their respective methods. In each of these methods, you call [NSApp endSheet:self.sheet]. This tells NSApp that it should then call the sheetDidEnd:returnCode:contextInfo: method on the object specified to be the modal delegate. In sheetDidEnd:returnCode:contextInfo: you then tell the sheet to hide itself.

    EDIT:

    Every NSWindow has a “Visible at launch” flag that can be set in Interface Builder. If this flag is set, the window will be visible at the time the nib file is loaded. If it isn’t set, the window is hidden until you programmatically show it. Just edit the flag in the nib file like shown:

    enter image description here

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

Sidebar

Related Questions

i m new to this android application development i would be very much grateful
I am very much new to the blackberry UI development and want to know
Very new to this, and I have no idea where to start. I want
I am very much new to this word ESX. We recently decided to upgrade
I'm working on a small Java applet, very much new to this programming thing.
Possible Duplicate: Android FTP Library I am very much new to the android development,
Very much new to web development and Jekyll, and trying to implement TapirGo into
i am very much new to Entity Framework and i just used this in
I am very much new to this JSON objects. So I need some helps
Iam asking this because iam very much new to stored procedure. Can any help

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.