DotMac

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

Load Nib File/別のNibを読み込む

(1)Create nib by IB

Make File's Owner a Custom Class e.g. HogeClass

Name this nib as Hoge.nib in this example.



(2)Create these files

HogeClass.h

HogeClass.m



HogeClass.h:

...

IBOutlet id hogeOutlet

...



HogeClass.m:


- (id)init

{

    self = [super init];

    if (self) {

// load nib

[NSBundle loadNibNamed:@"Hoge"  owner:self];

}

    return self;

}



と記載


(3)From another class, call HogeClass and its nib like this:


HogeClass* hogeInstance = [[HogeClass alloc] init];


とする。hogeInstanceを介してhogeOutletにアクセスできる。

 

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