On 22.08.2016 at 17:30 Ken Thomases wrote:

> On Aug 22, 2016, at 8:26 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:

>> I've created an NSAlert dialog as described here:
>> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Dialog/Tasks/UsingAlerts.html#//apple_ref/doc/uid/20000871-129009-BCIFAAEJ
>>  

>> When I run it using

>>   [alert runModal];

>> it shows up correctly but pressing a button doesn't do anything on 10.6. The
>> dialog isn't closed and just stays there. On 10.11, however, everything is
>> working correctly. Pressing a button closes the dialog and returns the id
>> of the button that has been pressed.

>> Since NSAlert is quite an essential class, I don't think that this is a bug
>> in 10.6 so I'm probably doing something wrong. Does anybody have an idea
>> what could cause this behaviour on 10.6 and how I can fix this?

> Tell us more about the context.  Is this a normal app or is it
> unusual in some way? 

It is unusual in the way that it's not calling NSApplicationMain() but tries
to imitate what NSApplicationMain() does. Here goes the code that is executed
to set up the NSApp:

        pool = [[NSAutoreleasePool alloc] init];

        [MyApplication sharedApplication];

        [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

        appDelegate = [[MyApplicationDelegate alloc] init];

        [NSApp setDelegate:appDelegate];
        [NSApp run];

In "applicationDidFinishLaunching" I then do this to assume control over
the program again:

        [NSApp stop:nil];

        NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined 
location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0 windowNumber:0 
context:nil subtype:0 data1:0 data2:0];

        [NSApp postEvent:event atStart:YES];
        
Posting the dummy event in didFinishLaunching is necessary to make sure that 
[NSApp run]
returns. Otherwise it doesn't return before a real event comes in (e.g. by 
clicking
its icon in the dock.)

> 
> Is this in the same app from your other thread
> where you're trying to shoehorn Cocoa into a C-based program?  Can
> you reproduce the problem in a new, standard Cocoa app project?

Yup, see above ;)

> Are any exceptions logged to the console when you press the button
> on 10.6? 

No.

> 
> Does the button visually respond (depress/highlight) to
> your click and it's just that it doesn't take effect?  Or does it not even 
> respond to the click?

No, it responds visually when clicking it, see also below. The dialog boxes can
be controlled just fine, they just cannot be dismissed by clicking the buttons. 

> Are you running the alert from the main/original thread or a secondary thread?

Main thread of course.

UPDATE: It seems to be a general problem with "runModal" because NSOpenPanel 
and NSSavePanel
show the very same behaviour. The dialogs can be controlled just fine, i.e. the 
user can
enter a filename, browse through directories, select files *BUT* it's not 
possible to close
the dialogs by clicking the buttons. The dialogs always stay open and 
"runModal" never
returns! I'm really wondering what is causing this...

-- 
Best regards,
 Andreas Falkenhahn                            mailto:andr...@falkenhahn.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to