| Home 目次>ApplicationKit>NSDocument | |
initWithContentsOfFile:ofType:
ファイルからドキュメントオブジェクトを初期化して返します
-(id) initWithContentsOfFile:(NSString *)fileName
ofType:(NSString *)docType
【返り値】 | |
| id | NSDocumentオブジェクト |
| 【パラメータ】 | |
| fileName | ファイル名 |
| docType | 文書タイプ |
【解説】
ファイルからドキュメントオブジェクト(NSDocument)を初期化して返します。
【例文】
#import "MyObject.h"
#import "MyDocument.h"
@implementation MyObject
- ( IBAction )myAction:( id )sender
{
// 開けるファイル拡張子の配列
NSArray *fileTypes = [ NSArray arrayWithObjects : @"txt" , @"'TEXT'" , nil ];
//OpenPanel を作る
NSOpenPanel *opPanel = [ NSOpenPanel openPanel ];
//
MyDocument *doc;
//OpenPanel の結果のボタン番号
int opRet;
//OpenPanel でファイル選択
opRet = [ opPanel runModalForDirectory : NSHomeDirectory() // どこのディレクトリを出すか
file : @"Documents" // どのファイルを選択しておくか
types : fileTypes ]; // 選べるファイルタイプ
if ( opRet == NSOKButton ) { // OPENPanel のボタンが OK なら
// ファイルから読み込む
doc = [[MyDocument alloc] initWithContentsOfFile:[opPanel filename] ofType: @"txt" ];
}
}
@end
![]() | |
この記事を評価してください。
| Home 目次>ApplicationKit>NSDocument | 修正日2006.12.26 |