开发者

how to load a class in Objective-C

开发者 https://www.devze.com 2022-12-19 04:15 出处:网络
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 l

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

精彩评论

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

关注公众号