DotMac

プログラムに関する覚え書き等

NSSavePanel (opening save dialogue)

EXAMPLE (modal dialogue)

/*これでモーダルダイアログ保存ができる。array A + array B の形式

- (IBAction)saveTable:(id)sender
{
	NSSavePanel* aPanel = [NSSavePanel savePanel];
	if( [aPanel runModal] == NSFileHandlingPanelOKButton ){
		NSArray *myArray;
		myArray = [NSArray arrayWithObjects:myTableView1Data_A, myTableView1Data_B, NULL];
		[myArray writeToFile:[aPanel filename] atomically:YES];
	}
}
*/


EXAMPLE (sheet)

- (IBAction)saveTable:(id)sender
{
	void* contextInfo;
	NSSavePanel* aPanel = [NSSavePanel savePanel];
	[aPanel beginSheetForDirectory:NULL
							  file:@"Replace Data"
					modalForWindow:[myTextView window]
					 modalDelegate:self
					didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:)
					   contextInfo:contextInfo];
	///
}

- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
	if( returnCode == NSFileHandlingPanelOKButton ){
		NSArray *myArray;
		myArray = [NSArray arrayWithObjects:myTableView1Data_A, myTableView1Data_B, NULL];
		[myArray writeToFile:[sheet filename] atomically:YES];
	}
}

///
///open

- (IBAction)loadTable:(id)sender
{
	[self quitTableEditing];
	void* contextInfo;
	NSOpenPanel* aPanel = [NSOpenPanel openPanel];
	[aPanel beginSheetForDirectory:NULL
							  file:NULL
							 types:NULL
					modalForWindow:[myTextView window]
					 modalDelegate:self
					didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
					   contextInfo:contextInfo];
	///
}
- (void)openPanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
	if( returnCode == NSFileHandlingPanelOKButton ){
		NSMutableArray *myArray = [ [NSMutableArray alloc] initWithContentsOfFile:[sheet filename]];
		[myTableView1Data_A release];
		[myTableView1Data_B release];		
		myTableView1Data_A = [[NSMutableArray alloc] initWithArray:[myArray objectAtIndex:0] ];
		myTableView1Data_B = [[NSMutableArray alloc] initWithArray:[myArray objectAtIndex:1] ];	
		[myTableView1 reloadData];
		[myArray release];
	}
}

 

Parting Words (著作権, 連絡先情報, etc.)