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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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
NSFormatterattached to your text field cell and then in yourNSTextFieldDelegateyou 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
NSFormattersubclass is something like this:You would assign the formatter to your text field like so:
And then in your
NSTextFieldDelegateyou handle any invalid input: