Below is how I invoke the dialog and below is the class itself.
I've also uploaded a simple test project that is the Apple
"Currency Converter" project with my minor additions for the dialog
( if someone should be willing to take a look it's available here -
100 kB download).
http://www.ronimusic.com/download/TestDialog_Cocoa.zip
I'm obviously doing something wrong? Can't figure out what?
Thanks for any help
Rolf
//--------------------------------------------------------------------
-------------------------------------------
- (IBAction)testDialog:(id)sender
{
MyTestController *pMyTestController;
pMyTestController = [[MyTestController alloc] init]; // create an
instance of my object, also loads the Nib file
NSWindow *win = [pMyTestController window]; // at this point
another instance of my object is created
NSModalSession session = [NSApp beginModalSessionForWindow:win];
// seems to operate on the second instance of my class
while ([NSApp runModalSession:session] == NSRunContinuesResponse)
{
// avoid CPU usage by not polling the event loop all the time.
usleep(200*1000); // 200 milliSec
}
[NSApp endModalSession:session];
[win orderOut: 0];
// this returns the values from the first instance of my class and
is completely wrong
if ([pMyTestController didCancel])
printf("pMyTestController reports I clicked the Cancel button \n");
else
printf("pMyTestController reports I clicked the OK button \n");
[pMyTestController release];
}
//--------------------------------------------------------------------
-------------------------------------------
// the class definition
@interface MyTestController : NSWindowController
{
IBOutlet NSButton *mOKButton;
IBOutlet NSButton *mCancelButton;
bool m_bDidCancel;
}
- (bool)didCancel;
- (IBAction)OKButtonAction:(id)sender;
- (IBAction)CancelButtonAction:(id)sender;
@end
//--------------------------------------------------------------------
-------------------------------------------
// the class implementation
#import "MyTestController.h"
@implementation MyTestController
- (id)init
{
m_bDidCancel = false;
return [super initWithWindowNibName:@"MyTestDlg"];
}
- (void)dealloc
{
[super dealloc];
}
-(void)awakeFromNib
{
m_bDidCancel = false;
}
- (bool)didCancel
{
return m_bDidCancel;
}
- (IBAction)OKButtonAction:(id)sender
{
m_bDidCancel = false;
[NSApp stopModal];
}
- (IBAction)CancelButtonAction:(id)sender
{
m_bDidCancel = true;
[NSApp stopModal];
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40chello.se
This email sent to email@hidden