Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 创建运行时已知的类的实例_Iphone_Ios_Class_Runtime_Instantiation - Fatal编程技术网

Iphone 创建运行时已知的类的实例

Iphone 创建运行时已知的类的实例,iphone,ios,class,runtime,instantiation,Iphone,Ios,Class,Runtime,Instantiation,我有这段代码,但它返回nil而不是一个新类。 在这里它是无用的,但在我的程序中它是有意义的 Class myClass = [SettingsTableViewController class]; UIViewController *targetViewController = [[myClass alloc] initWithNibName:nil bundle:nil]; [[self navigationController] pushViewControll

我有这段代码,但它返回nil而不是一个新类。 在这里它是无用的,但在我的程序中它是有意义的

    Class myClass = [SettingsTableViewController class];  

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

你忘记了什么,或者你可能不知道。这是正确的代码

Class myClass = NSCLassFromString(@"yourClassName");

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

如果您的类没有nib,则当您按下导航控制器时,它将无法工作。是的,视图是以编程方式描述的。谢天谢地,问题出在别处了,在一次竞选中,他早早就以零告终。我发布的代码正在运行。