• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Dialog problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dialog problem


  • Subject: Dialog problem
  • From: Roni Music <email@hidden>
  • Date: Thu, 14 Sep 2006 12:39:32 +0200


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.


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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Dialog problem
      • From: Tommy Nordgren <email@hidden>
  • Prev by Date: Bindings / Core Data: Ensuring a value is unique
  • Next by Date: Re: Populate NSTextView from NSPopupButton
  • Previous by thread: Re: Bindings / Core Data: Ensuring a value is unique
  • Next by thread: Re: Dialog problem
  • Index(es):
    • Date
    • Thread