开发者

Create an instance of a class known at runtime

I have this code but it开发者_开发问答 returns "nil" instead of a new class. Here it is useless but in my programme it makes sens.

    Class myClass = [SettingsTableViewController class];  

    UIViewController *targetViewController = [[myClass alloc] initWithNibName:nil bundle:nil];
    [[self navigationController] pushViewController:targetViewController animated:YES];


You are forgetting something or you might don't know. Here is the proper code.

Class myClass = NSCLassFromString(@"yourClassName");

if(myClass){
   myClass = [[yourclassName alloc] init];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜