> On 26 Mar 2015, at 10:57 pm, Dave <[email protected]> wrote:
> 
> i tried this just to get something working for now, but it doesn’t seem to 
> affect where the Alert is displayed.
> 
> myAlert = [NSAlert alertWithMessageText:@"Do you really want to do that?" 
> defaultButton:@“No" alternateButton:@“Yes" otherButton:nil 
> informativeTextWithFormat:@"It might cause mayhem!”];
> 
> myAlertWindow = myAlert.window;
> myAlertWindowFrameRect = myAlertWindow.frame;
> myAlertWindowFrameRect.origin = myNewOrigin;
> [myAlertWindow setFrame:myAlertWindowFrameRect display:YES];
> 
> myAlertResponse = [myAlert runModal];
> if (myAlertResponse == kDialogResponseYes)
>       {
>       }
> else
>       {
>       }
> 



At the point you're setting the frame, the window isn't visible. -runModal 
shows the window if necessary and positions it on screen, overriding the frame 
you set. If you force it to be visible before -runModal is called, the frame 
position you set is not changed. This works:


        NSAlert* alert = [NSAlert alertWithMessageText:@"hello" 
defaultButton:@"ok" alternateButton:@"cancel" otherButton:nil 
informativeTextWithFormat:@"bing bang wallah wallah bang"];
        
        [alert.window setFrameOrigin:NSMakePoint( 10, 100)];
        [alert.window makeKeyAndOrderFront:nil];
        
        NSInteger result = [alert runModal];
        
        
        NSLog(@"response = %ld", result);


> I’ll investigate doing it using a sheet next week, but it would be nice to 
> have the Alert working in the meantime.


Your requirement isn't clear - do you want a sheet to appear as if unattached 
to a host window, just floating in space? Even if you can achieve it, users 
will simply assume your app is buggy. Ideas like this are never seen in the 
wild for good reason.

--Graham



_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to