Re: Dialog problem
Re: Dialog problem
- Subject: Re: Dialog problem
- From: Tommy Nordgren <email@hidden>
- Date: Thu, 14 Sep 2006 13:11:06 +0200
On Sep 14, 2006, at 12:39 PM, Roni Music wrote:
Hi,
I'm a newbie with Cocoa/Objective-C, mostly been using C++ and Carbon.
I'm trying to implement a simple dialog and to get the settings
back after it is closed.
The problem I encounter is that there are being created two
instances of the MyTestController class although I'm only creating
one myself.
The interaction with the dialog is performed by the second class,
so after closing it, the first object haven't changed at all.
You have probably a copy of your controller class in your nib file.
Open your nib file and perform the following steps
(it won't hurt to make a backup first)
1. Delete your controller instance.
2. Drag your controller header onto the nib window.
3. Set the class of icon Files Owner to your controller class.
4. Reconnect Actions and Outlets previously leading to the controller
in the nib, to symbol Files Owner
5. Rebuild your project
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
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden