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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:06:31+00:00 2026-05-27T05:06:31+00:00

How do I display a popup informing a NSTextField can’t be empty in cocoa

  • 0

How do I display a popup informing a NSTextField can’t be empty in cocoa ?

If the user click apply and the NSTextField is empty a popup should appear saying the field can’t be empty.

thanks

  • 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-27T05:06:32+00:00Added an answer on May 27, 2026 at 5:06 am

    The answer by @beryllium only tells part of the story.

    In fact, to properly validate text field input in Cocoa you should be using an NSFormatter attached to your text field cell and then in your NSTextFieldDelegate you should implement the method: control:didFailToFormatString:errorDescription:. In this delegate method you can prompt the user to correct their input.

    All you need to do in your NSFormatter subclass is something like this:

    @implementation RKTextFormatter
    
    - (NSString*)stringForObjectValue:(id)object 
    {
        return (NSString*)object;
    }
    
    - (BOOL)getObjectValue:(id*)object forString:(NSString*)string errorDescription:(NSString**)error {
    
        BOOL stringPassesTest = NO;
    
        //put your test here 
    
        if(!stringPassesTest)
        {
            //set the error and return NO
            if(error)
                *error = [NSError errorWithDomain:@"YourErrorDomain" code:1 userInfo:[NSDictionary dictionaryWithObject:@"It's a bingo" forKey:NSLocalizedDescriptionKey]];
            return NO;
        }
    
        //otherwise, just assign the string
        *object = string;
        return YES;
    }
    @end
    

    You would assign the formatter to your text field like so:

    RKTextFormatter* formatter = [[RKTextFormatter alloc] init];
    [[textField cell] setFormatter:formatter];
    

    And then in your NSTextFieldDelegate you handle any invalid input:

    - (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error
    {
    //display an alert, obviously it would be more useful than this
    NSAlert* alert = [NSAlert alertWithMessageText:@"You have failed me for the last time" defaultButton:@"Revise Input" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@",error];
    
    [alert beginSheetModalForWindow:control.window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
    
    //if you return NO here, the user's input will not be accepted
    //and the field will remain in focus
    return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to display a popup-div below the mouse cursor, but it should
I need to display a popup window when a user clicks a hyperlink on
I have to display a popup when user clicks on Place button inside a
I have sales application. When the user click on EditText the popup calculator want
I want to display a popup windo on my rails application... Here is exactly
When I use Toast to display some popup text on the screen, it displays
I want to hover over a table element, and display a popup box in
I want to display script errors in a popup alert instead of showing them
I'm using Fancybox to display a popup window, set as type: 'ajax' so I
I have created a static method to display a popup on my website from

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.