开发者

Create an instance of a class known at runtime

开发者 https://www.devze.com 2023-03-15 01:38 出处:网络
I have this code but it开发者_开发问答 returns \"nil\" instead of a new class. Here it is useless but in my programme it makes sens.

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

精彩评论

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