Re: error details in a NSAlert
Re: error details in a NSAlert
- Subject: Re: error details in a NSAlert
- From: Fritz Anderson <email@hidden>
- Date: Mon, 07 Apr 2014 14:51:13 -0500
On 6 Apr 2014, at 2:52 PM, Daniel Luis dos Santos <email@hidden> wrote:
> I want to display some text indicating a list of errors the user should correct before submitting data.
>
> I am using a modal NSAlert in which i set a message with a localised string from a table.
>
> I want to include the error details and for that I was setting the informativeText field but it doesn’t show up unless its a string literal. I need it to be a variable value.
That’s not what I see. I made a quick experiment, with the stock Cocoa/AppKit template. I dropped a text field into the window, and a button to trigger an alert. doAlert: harvests the informative-text string from the field, which means the string can vary.
Everything else is the same as your code (stripped of the accessory view, which you describe as being merely an attempt to work around the failure of the informative text to appear). Note that you should set the informative-text format to the string you want to display; use %@ and then the string.
What this suggests to me is that your “informativeText” variable is not what you assume it is. Have you set a breakpoint before you create the alert, and inspected it?
— F
#import "KVAAppDelegate.h"
@interface KVAAppDelegate ()
@property (weak) IBOutlet NSButton *alertButton;
- (IBAction)doAlert:(id)sender;
@property (weak) IBOutlet NSTextField *informativeField;
@end
@implementation KVAAppDelegate
- (void) awakeFromNib
{
self.informativeField.stringValue = @"This space for rent.";
}
- (IBAction) doAlert: (id) sender
{
NSString * informativeText = self.informativeField.stringValue;
NSAlert * errorAlert;
errorAlert = [NSAlert
alertWithMessageText:
NSLocalizedStringFromTable(
@"The user data is not valid. Correct it and try again",
@"AccountInfoTab",
@"The user data is not valid. Correct it and try again"
)
defaultButton: nil
alternateButton: nil
otherButton: nil
informativeTextWithFormat: @"%@", informativeText];
[errorAlert runModal];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden