根据类名创建ViewController



NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]]; //创建视图控制器的Class //使用class间接使用类名,即使不加头文件,也能创建对象。 //编译器要求直接引用类名等标识符,必须拥有声明。 Class aVCClass = NSClassFromString(className); //创建vc对象 UIViewController * vc = [[aVCClass alloc] init]; [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]]; [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]]; NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]]; //创建视图控制器的Class //使用class间接使用类名,即使不加头文件,也能创建对象。 //编译器要求直接引用类名等标识符,必须拥有声明。 Class aVCClass = NSClassFromString(className); //创建vc对象 UIViewController * vc = [[aVCClass alloc] init]; [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]]; [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]];
    NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]];

    //创建视图控制器的Class
    //使用class间接使用类名,即使不加头文件,也能创建对象。
    //编译器要求直接引用类名等标识符,必须拥有声明。
    Class aVCClass = NSClassFromString(className);
    //创建vc对象
    UIViewController * vc = [[aVCClass alloc] init];
    [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]];
    [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]];



版权声明:本文为jyt199011302原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。