开发者

how to load a class in Objective-C

How to load a class in Objective-C for iPhone application? I know tat Bundling concept is in MAC , but for iPhone can i use the same bundle c开发者_JAVA技巧oncept to load a class?


What do you want to load? If you want to load a class from a nib you'd simply do something like:

YourClassName *classInstance = [[YourClassName alloc] initWithNibName:@"YourClassName" bundle:Nil];

Only some classes will implement the initWithNibName, such as UIViewControllers. You can also load a class from a nib from your bundle to an owner using the following:

[[NSBundle mainBundle] loadNibNamed:@"YourClassName" owner:self options:nil];


I use the way as follows

    Class c = NSClassFromString( YourClassNameHere );


YourClass* ojectInstance = [c new];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜