Skip navigation.
 
mlRe: Alert Sheets hard wired in Interface Builder
FROM : Nathan Kinsinger
DATE : Sun Jun 01 21:15:34 2008

On Jun 1, 2008, at 12:19 PM, John Love wrote:

> 1) I found the culprit on the sheet appearing as a separate window, 
> and not
> a sheet .. you were right cause somehow the passed docWindow was 
> apparently
> nil .. anyway, called my sheet routine from a different part of 
> MyDocument.m
> .. and now the sheet appears as a sheet.
>
> 2) the problem remaining centers on accessing the various buttons on 
> the
> alert sheet


You have several issues here:

First, you can't cast the NSAlert to an NSWindow. The 
endCalculateSheet:code:info: method must have the same types as the 
prototype.

Second, the returnCodes for the buttons will be 
NSAlertFirstButtonReturn, NSAlertSecondButtonReturn and 
NSAlertThirdButtonReturn. The ones you used are only valid if you call 
alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat
:.

Third, you don't need to close or orderOut the NSAlert because it will 
automatically close when your endCalculateSheet:code:info: method 
finishes.

See below:

- (void) showCalculateSheet:(NSWindow*)docWindow
{
   NSAlert *calculateSheet = [[[NSAlert alloc] init] autorelease];
   
   [calculateSheet addButtonWithTitle:@"Continue"];
   [calculateSheet addButtonWithTitle:@"Stop and save"];
   [calculateSheet addButtonWithTitle:@"Stop and don't save"];
   [calculateSheet setMessageText:@"Do you wish to continue 
calculating?"];
   [calculateSheet setInformativeText:@"You have not finished 
calculating your Spreadsheet."];
   [calculateSheet setAlertStyle:NSWarningAlertStyle];
   
   [calculateSheet beginSheetModalForWindow:docWindow
                             modalDelegate:self
                             didEndSelector:@selector(endCalculateSheet:code:info:)
                                contextInfo:docWindow];
}

- (void) endCalculateSheet:(NSAlert*)theSheet code:(int)returnCode 
info:(void*)contextInfo
{
   if (returnCode == NSAlertFirstButtonReturn)          // "Continue"
   {
       NSLog(@"Continue button clicked");
   }
   else if (returnCode == NSAlertSecondButtonReturn)      // "Stop and 
save"
   {
       NSLog(@"Stop and save button clicked");
   }
   else if (returnCode == NSAlertThirdButtonReturn)  // "Stop and don't 
save"
   {
       NSLog(@"Stop and don't save button clicked");
   }
}

--Nathan

Related mailsAuthorDate
mlAlert Sheets hard wired in Interface Builder John Love May 27, 22:28
mlRe: Alert Sheets hard wired in Interface Builder Sherman Pendley May 27, 22:38
mlRe: Alert Sheets hard wired in Interface Builder Kyle Sluder May 27, 22:40
mlRe: Alert Sheets hard wired in Interface Builder Jens Alfke May 28, 06:06
mlRe: Alert Sheets hard wired in Interface Builder Graham Cox May 28, 06:24
mlRe: Alert Sheets hard wired in Interface Builder Scott Ribe May 29, 05:29
mlRe: Alert Sheets hard wired in Interface Builder Kyle Sluder May 29, 05:38
mlRe: Alert Sheets hard wired in Interface Builder Jens Alfke May 29, 05:39
mlRe: Alert Sheets hard wired in Interface Builder Graham Cox May 29, 05:58
mlRe: Alert Sheets hard wired in Interface Builder Chris Hanson May 29, 07:44
mlRe: Alert Sheets hard wired in Interface Builder John Love May 31, 17:43
mlRe: Alert Sheets hard wired in Interface Builder John Love May 31, 18:40
mlRe: Alert Sheets hard wired in Interface Builder Keary Suska May 31, 19:08
mlRe: Alert Sheets hard wired in Interface Builder Jens Alfke May 31, 19:22
mlRe: Alert Sheets hard wired in Interface Builder John Love Jun 1, 20:19
mlRe: Alert Sheets hard wired in Interface Builder Jens Alfke Jun 1, 21:07
mlRe: Alert Sheets hard wired in Interface Builder Nathan Kinsinger Jun 1, 21:15
mlRe: Alert Sheets hard wired in Interface Builder John Love Jun 3, 22:27